How to give one column space in every next row of grid display












2















I have a few divs and I want to leave the space of one div on the left side in every subsequent row of the grid. For instance, I want to have 4 div boxes in the first row, 3 div boxes in the second row, 2 boxes in the third row and so on.



Example



enter image description here



CSS



    .wrapper {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-gap: 1px;
grid-auto-flow: row;
grid-auto-rows: 100px 100px;
}
* {box-sizing: border-box;}
.wrapper > div {

border-radius: 5px;
background-color: #DCE0E7;

padding: 1em;
color: #d9480f;
}


HTML



    <div class="wrapper">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
<div>Six</div>
<div>Seven</div>
<div>Eight</div>
<div>nine</div>
<div>ten</div>
</div>









share|improve this question

























  • like a reversed floor steps?

    – Viira
    Nov 14 '18 at 7:15


















2















I have a few divs and I want to leave the space of one div on the left side in every subsequent row of the grid. For instance, I want to have 4 div boxes in the first row, 3 div boxes in the second row, 2 boxes in the third row and so on.



Example



enter image description here



CSS



    .wrapper {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-gap: 1px;
grid-auto-flow: row;
grid-auto-rows: 100px 100px;
}
* {box-sizing: border-box;}
.wrapper > div {

border-radius: 5px;
background-color: #DCE0E7;

padding: 1em;
color: #d9480f;
}


HTML



    <div class="wrapper">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
<div>Six</div>
<div>Seven</div>
<div>Eight</div>
<div>nine</div>
<div>ten</div>
</div>









share|improve this question

























  • like a reversed floor steps?

    – Viira
    Nov 14 '18 at 7:15
















2












2








2








I have a few divs and I want to leave the space of one div on the left side in every subsequent row of the grid. For instance, I want to have 4 div boxes in the first row, 3 div boxes in the second row, 2 boxes in the third row and so on.



Example



enter image description here



CSS



    .wrapper {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-gap: 1px;
grid-auto-flow: row;
grid-auto-rows: 100px 100px;
}
* {box-sizing: border-box;}
.wrapper > div {

border-radius: 5px;
background-color: #DCE0E7;

padding: 1em;
color: #d9480f;
}


HTML



    <div class="wrapper">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
<div>Six</div>
<div>Seven</div>
<div>Eight</div>
<div>nine</div>
<div>ten</div>
</div>









share|improve this question
















I have a few divs and I want to leave the space of one div on the left side in every subsequent row of the grid. For instance, I want to have 4 div boxes in the first row, 3 div boxes in the second row, 2 boxes in the third row and so on.



Example



enter image description here



CSS



    .wrapper {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-gap: 1px;
grid-auto-flow: row;
grid-auto-rows: 100px 100px;
}
* {box-sizing: border-box;}
.wrapper > div {

border-radius: 5px;
background-color: #DCE0E7;

padding: 1em;
color: #d9480f;
}


HTML



    <div class="wrapper">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
<div>Six</div>
<div>Seven</div>
<div>Eight</div>
<div>nine</div>
<div>ten</div>
</div>






css html5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 8:44









ProgrammerPer

601713




601713










asked Nov 14 '18 at 6:34









samsam

294




294













  • like a reversed floor steps?

    – Viira
    Nov 14 '18 at 7:15





















  • like a reversed floor steps?

    – Viira
    Nov 14 '18 at 7:15



















like a reversed floor steps?

– Viira
Nov 14 '18 at 7:15







like a reversed floor steps?

– Viira
Nov 14 '18 at 7:15














1 Answer
1






active

oldest

votes


















3














just using css without using javascript or scss, using nth-child() can help to create something like this.






/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>








share|improve this answer


























  • yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

    – sam
    Nov 14 '18 at 7:31











  • I updated it to start from left one.

    – RGhanbari
    Nov 14 '18 at 7:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294353%2fhow-to-give-one-column-space-in-every-next-row-of-grid-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














just using css without using javascript or scss, using nth-child() can help to create something like this.






/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>








share|improve this answer


























  • yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

    – sam
    Nov 14 '18 at 7:31











  • I updated it to start from left one.

    – RGhanbari
    Nov 14 '18 at 7:37
















3














just using css without using javascript or scss, using nth-child() can help to create something like this.






/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>








share|improve this answer


























  • yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

    – sam
    Nov 14 '18 at 7:31











  • I updated it to start from left one.

    – RGhanbari
    Nov 14 '18 at 7:37














3












3








3







just using css without using javascript or scss, using nth-child() can help to create something like this.






/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>








share|improve this answer















just using css without using javascript or scss, using nth-child() can help to create something like this.






/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>








/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>





/* Start from left*/
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: left;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(6){
margin-left: 20%;
}
.wrapper > div:nth-child(10){
margin-left: 40%;
}
.wrapper > div:nth-child(13){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}
/* Start from right*/
/*.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper > div{
width: 20%;
float: right;
height: 40px;
border:1px solid #aaa;
}
.wrapper > div:nth-child(9){
margin-left: 20%;
}
.wrapper > div:nth-child(12){
margin-left: 40%;
}
.wrapper > div:nth-child(14){
margin-left: 60%;
}
.wrapper > div:nth-child(15){
margin-left: 80%;
}*/

<!doctype html>

<html>
<head>
</head>

<body>
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
</div>
</body>
</html>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 7:35

























answered Nov 14 '18 at 7:25









RGhanbariRGhanbari

944




944













  • yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

    – sam
    Nov 14 '18 at 7:31











  • I updated it to start from left one.

    – RGhanbari
    Nov 14 '18 at 7:37



















  • yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

    – sam
    Nov 14 '18 at 7:31











  • I updated it to start from left one.

    – RGhanbari
    Nov 14 '18 at 7:37

















yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

– sam
Nov 14 '18 at 7:31





yes exactly it is what i wanted. thanx alot. can you just do like start with with number one div, not 5..

– sam
Nov 14 '18 at 7:31













I updated it to start from left one.

– RGhanbari
Nov 14 '18 at 7:37





I updated it to start from left one.

– RGhanbari
Nov 14 '18 at 7:37




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294353%2fhow-to-give-one-column-space-in-every-next-row-of-grid-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values