Using “display: grid” to align tiles flush as well as stacked











up vote
-4
down vote

favorite












I am building a photo album. Each photo is a tile with an image (uniform size) and a title and description (not uniform size). There is a "toggle" switch that will display the tiles either "flush", or "stacked". I do not know the total number of tiles beforehand.



I think I can do the "flush" version, but I am new to grids and maybe got it wrong. I am totally at a loss for the "stacked" example code.



Flush Version



I want to display them, 3 across, then wrap. But when they wrap, I need them to start again at the bottom of whatever was the deepest tile in the row above. (See Option 1 image below, and this codepen link to see it in action.)






div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>





Option 1 image



Stacked Version



In some instances, I again want to display 3 across, but when they wrap, have them "fit into" the row above. I am calling this "stacked".(See Option 2)



Option 2 image



Two caveats:
I want to use as little CSS and HTML as possible.
And I want to use as much of the same CSS as possible. (I am hoping the CSS will be the same, but with one or two different properties.)










share|improve this question
























  • Please read How to Ask and then edit your question accordingly.
    – LGSon
    Nov 21 at 19:08












  • @LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
    – Gavin R
    Nov 21 at 19:24






  • 1




    Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
    – LGSon
    Nov 21 at 19:31

















up vote
-4
down vote

favorite












I am building a photo album. Each photo is a tile with an image (uniform size) and a title and description (not uniform size). There is a "toggle" switch that will display the tiles either "flush", or "stacked". I do not know the total number of tiles beforehand.



I think I can do the "flush" version, but I am new to grids and maybe got it wrong. I am totally at a loss for the "stacked" example code.



Flush Version



I want to display them, 3 across, then wrap. But when they wrap, I need them to start again at the bottom of whatever was the deepest tile in the row above. (See Option 1 image below, and this codepen link to see it in action.)






div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>





Option 1 image



Stacked Version



In some instances, I again want to display 3 across, but when they wrap, have them "fit into" the row above. I am calling this "stacked".(See Option 2)



Option 2 image



Two caveats:
I want to use as little CSS and HTML as possible.
And I want to use as much of the same CSS as possible. (I am hoping the CSS will be the same, but with one or two different properties.)










share|improve this question
























  • Please read How to Ask and then edit your question accordingly.
    – LGSon
    Nov 21 at 19:08












  • @LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
    – Gavin R
    Nov 21 at 19:24






  • 1




    Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
    – LGSon
    Nov 21 at 19:31















up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











I am building a photo album. Each photo is a tile with an image (uniform size) and a title and description (not uniform size). There is a "toggle" switch that will display the tiles either "flush", or "stacked". I do not know the total number of tiles beforehand.



I think I can do the "flush" version, but I am new to grids and maybe got it wrong. I am totally at a loss for the "stacked" example code.



Flush Version



I want to display them, 3 across, then wrap. But when they wrap, I need them to start again at the bottom of whatever was the deepest tile in the row above. (See Option 1 image below, and this codepen link to see it in action.)






div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>





Option 1 image



Stacked Version



In some instances, I again want to display 3 across, but when they wrap, have them "fit into" the row above. I am calling this "stacked".(See Option 2)



Option 2 image



Two caveats:
I want to use as little CSS and HTML as possible.
And I want to use as much of the same CSS as possible. (I am hoping the CSS will be the same, but with one or two different properties.)










share|improve this question















I am building a photo album. Each photo is a tile with an image (uniform size) and a title and description (not uniform size). There is a "toggle" switch that will display the tiles either "flush", or "stacked". I do not know the total number of tiles beforehand.



I think I can do the "flush" version, but I am new to grids and maybe got it wrong. I am totally at a loss for the "stacked" example code.



Flush Version



I want to display them, 3 across, then wrap. But when they wrap, I need them to start again at the bottom of whatever was the deepest tile in the row above. (See Option 1 image below, and this codepen link to see it in action.)






div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>





Option 1 image



Stacked Version



In some instances, I again want to display 3 across, but when they wrap, have them "fit into" the row above. I am calling this "stacked".(See Option 2)



Option 2 image



Two caveats:
I want to use as little CSS and HTML as possible.
And I want to use as much of the same CSS as possible. (I am hoping the CSS will be the same, but with one or two different properties.)






div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>





div.tri-grid {
overflow: hidden;
grid-gap: 1em;
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: repeat(3,auto);
align-content: space-around;
justify-content: space-between;
overflow: hidden;
}

.tile {
background-color: #ccc;
padding: 1em;
}

.tile-1 { height: 200px; }
.tile-2 { height: 160px; }
.tile-3 { height: 180px; }
.tile-4 { height: 100px; }
.tile-5 { height: 150px; }
.tile-6 { height: 195px; }

<div class="tri-grid">
<div class="tile tile-1">
tile 1
</div>
<div class="tile tile-2">
tile 2
</div>
<div class="tile tile-3">
tile 3
</div>
<div class="tile tile-4">
tile 4
</div>
<div class="tile tile-5">
tile 5
</div>
<div class="tile tile-6">
tile 6
</div>
</div>






css layout grid






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 20:24









rene

33.2k1178104




33.2k1178104










asked Nov 21 at 18:36









Gavin R

14




14












  • Please read How to Ask and then edit your question accordingly.
    – LGSon
    Nov 21 at 19:08












  • @LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
    – Gavin R
    Nov 21 at 19:24






  • 1




    Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
    – LGSon
    Nov 21 at 19:31




















  • Please read How to Ask and then edit your question accordingly.
    – LGSon
    Nov 21 at 19:08












  • @LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
    – Gavin R
    Nov 21 at 19:24






  • 1




    Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
    – LGSon
    Nov 21 at 19:31


















Please read How to Ask and then edit your question accordingly.
– LGSon
Nov 21 at 19:08






Please read How to Ask and then edit your question accordingly.
– LGSon
Nov 21 at 19:08














@LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
– Gavin R
Nov 21 at 19:24




@LGSon I have revised it to make it more clear. (After re-reading the link you gave me.) If there is something else you had in mind, please tell me exactly. :)
– Gavin R
Nov 21 at 19:24




1




1




Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
– LGSon
Nov 21 at 19:31






Then have a read here, Minimal, Complete, and Verifiable example. Code should be within the question, not as external links.
– LGSon
Nov 21 at 19:31



















active

oldest

votes











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%2f53418549%2fusing-display-grid-to-align-tiles-flush-as-well-as-stacked%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53418549%2fusing-display-grid-to-align-tiles-flush-as-well-as-stacked%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

Berounka

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

Sphinx de Gizeh