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.)
css layout grid
add a comment |
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.)
css layout grid
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
add a comment |
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.)
css layout grid
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
css layout grid
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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