Two columns grid with flat mixed list of items









up vote
2
down vote

favorite












I'm trying to make two columns layout of flat list of random items where some should be on the left one under each other and others on the right.



So far i'm using css grid but i have an issue with "empty rows" because those cells do not know to "start from top".



If i add all of them grid-row-start: 1, they all just collapses above each other at the top.



I don't want to change structure of the container as i'd like to just shuffle the classes to move items. In theory i can add class like row-1, row-2 etc in JavaScript and use it to determine where the cell should start but I wonder if there is an cleaner way to approach this purely in css.



Demo: https://jsfiddle.net/mbynw4cL/1/



enter image description here










share|improve this question





















  • Can you please add your code here?
    – ksav
    Nov 9 at 14:43














up vote
2
down vote

favorite












I'm trying to make two columns layout of flat list of random items where some should be on the left one under each other and others on the right.



So far i'm using css grid but i have an issue with "empty rows" because those cells do not know to "start from top".



If i add all of them grid-row-start: 1, they all just collapses above each other at the top.



I don't want to change structure of the container as i'd like to just shuffle the classes to move items. In theory i can add class like row-1, row-2 etc in JavaScript and use it to determine where the cell should start but I wonder if there is an cleaner way to approach this purely in css.



Demo: https://jsfiddle.net/mbynw4cL/1/



enter image description here










share|improve this question





















  • Can you please add your code here?
    – ksav
    Nov 9 at 14:43












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to make two columns layout of flat list of random items where some should be on the left one under each other and others on the right.



So far i'm using css grid but i have an issue with "empty rows" because those cells do not know to "start from top".



If i add all of them grid-row-start: 1, they all just collapses above each other at the top.



I don't want to change structure of the container as i'd like to just shuffle the classes to move items. In theory i can add class like row-1, row-2 etc in JavaScript and use it to determine where the cell should start but I wonder if there is an cleaner way to approach this purely in css.



Demo: https://jsfiddle.net/mbynw4cL/1/



enter image description here










share|improve this question













I'm trying to make two columns layout of flat list of random items where some should be on the left one under each other and others on the right.



So far i'm using css grid but i have an issue with "empty rows" because those cells do not know to "start from top".



If i add all of them grid-row-start: 1, they all just collapses above each other at the top.



I don't want to change structure of the container as i'd like to just shuffle the classes to move items. In theory i can add class like row-1, row-2 etc in JavaScript and use it to determine where the cell should start but I wonder if there is an cleaner way to approach this purely in css.



Demo: https://jsfiddle.net/mbynw4cL/1/



enter image description here







javascript html css css-grid






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 14:06









Adam Szmyd

7741026




7741026











  • Can you please add your code here?
    – ksav
    Nov 9 at 14:43
















  • Can you please add your code here?
    – ksav
    Nov 9 at 14:43















Can you please add your code here?
– ksav
Nov 9 at 14:43




Can you please add your code here?
– ksav
Nov 9 at 14:43












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










So what you want is to use the grid-auto-flow property:






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





This will "fill in" the gaps.



See https://css-tricks.com/snippets/css/complete-guide-grid/#article-header-id-25 for more on CSS grid.






share|improve this answer




















  • Thank you so much!
    – Adam Szmyd
    yesterday










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',
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%2f53227239%2ftwo-columns-grid-with-flat-mixed-list-of-items%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










So what you want is to use the grid-auto-flow property:






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





This will "fill in" the gaps.



See https://css-tricks.com/snippets/css/complete-guide-grid/#article-header-id-25 for more on CSS grid.






share|improve this answer




















  • Thank you so much!
    – Adam Szmyd
    yesterday














up vote
3
down vote



accepted










So what you want is to use the grid-auto-flow property:






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





This will "fill in" the gaps.



See https://css-tricks.com/snippets/css/complete-guide-grid/#article-header-id-25 for more on CSS grid.






share|improve this answer




















  • Thank you so much!
    – Adam Szmyd
    yesterday












up vote
3
down vote



accepted







up vote
3
down vote



accepted






So what you want is to use the grid-auto-flow property:






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





This will "fill in" the gaps.



See https://css-tricks.com/snippets/css/complete-guide-grid/#article-header-id-25 for more on CSS grid.






share|improve this answer












So what you want is to use the grid-auto-flow property:






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





This will "fill in" the gaps.



See https://css-tricks.com/snippets/css/complete-guide-grid/#article-header-id-25 for more on CSS grid.






.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>





.grid 
width: 200px;
border: 1px solid green;
display: grid;
grid-template-columns: auto auto;
grid-auto-flow: dense;


.item
width: 30px;
height: 30px;
margin: 5px;


.item.left
grid-column-start: 1;
justify-self: start;
background: red;


.item.right
grid-column-start: 2;
justify-self: end;
background: blue;

<div class="grid">
<div class="item left"></div>
<div class="item left"></div>
<div class="item right"></div>
<div class="item right"></div>
<div class="item left"></div>
</div>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 14:36









Raad

3,00111534




3,00111534











  • Thank you so much!
    – Adam Szmyd
    yesterday
















  • Thank you so much!
    – Adam Szmyd
    yesterday















Thank you so much!
– Adam Szmyd
yesterday




Thank you so much!
– Adam Szmyd
yesterday

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227239%2ftwo-columns-grid-with-flat-mixed-list-of-items%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo