CSS grid empty cell issue









up vote
0
down vote

favorite












enter image description here



I'm trying to understand the nature of css grid, im somewhat new to it. I want to keep my grid items responsive and maintain the aspect ratio of the images. It seems that there is a weird gap on the bottom of the images.



I look at other questions that could be similar, still not sure.



here is what i have



https://codepen.io/eliowl/pen/EOgNQe



html



<section id="about" class="about">
<h3 class="text-center">About</h3>
<section class="grid">
<div class="grid-item --width3 ">
<img src="https://images.unsplash.com/photo-1541807084-5c52b6b3adef?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0c64fc542895cda41529f98ed3808572&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width ">
<img src="https://images.unsplash.com/photo-1541773477186-4133e93eb70e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=da73715faa685433b42f4decb9f71a60&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width2 ">
<img src="https://images.unsplash.com/photo-1541787975442-d5085a8ec678?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f6fc603cb3c4886ec55a1bff07ee7b53&auto=format&fit=crop&w=375&q=80" alt="">
</div>

<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541780050666-f64773a3d779?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=9ce82bea4ecf5b343e5317a683fd8226&auto=format&fit=crop&w=634&q=80" alt="">
</div>


<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541766029309-8d7fa5bb773b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f3d1bf633d2a601dd04a716acfce40be&auto=format&fit=crop&w=500&q=60" alt="">
</div>

</section>
</section>


scss



.grid
display: grid;
background-color: #fafafa;
max-width: 1300px;
clear: both;
margin: 0 auto;
grid-template-columns:1fr 1fr 1fr 1fr;
grid-auto-flow: dense;

grid-auto-rows: 100%;


.grid:after
content: '';
display: block;
clear: both;


.grid-item
display: flex;
position: relative;
overflow: hidden;
align-items:flex-start;
grid-column: auto / span 2;
grid-row: auto / span 4;



img
width: 100%;




.--width
grid-row: 2;



.--width2
grid-row: auto / span 4;










share|improve this question























  • Can you provide a codepen or a jsfiddle with the issue?
    – MartinBA
    Nov 11 at 2:35










  • ok, i updated it.
    – BARNOWL
    Nov 11 at 3:01










  • The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
    – Michael_B
    Nov 11 at 3:11






  • 1




    stackoverflow.com/q/44377343/3597276
    – Michael_B
    Nov 11 at 3:13







  • 1




    I commented the changes in the revised codepen. Also take a look at the link I posted.
    – Michael_B
    Nov 11 at 3:46














up vote
0
down vote

favorite












enter image description here



I'm trying to understand the nature of css grid, im somewhat new to it. I want to keep my grid items responsive and maintain the aspect ratio of the images. It seems that there is a weird gap on the bottom of the images.



I look at other questions that could be similar, still not sure.



here is what i have



https://codepen.io/eliowl/pen/EOgNQe



html



<section id="about" class="about">
<h3 class="text-center">About</h3>
<section class="grid">
<div class="grid-item --width3 ">
<img src="https://images.unsplash.com/photo-1541807084-5c52b6b3adef?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0c64fc542895cda41529f98ed3808572&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width ">
<img src="https://images.unsplash.com/photo-1541773477186-4133e93eb70e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=da73715faa685433b42f4decb9f71a60&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width2 ">
<img src="https://images.unsplash.com/photo-1541787975442-d5085a8ec678?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f6fc603cb3c4886ec55a1bff07ee7b53&auto=format&fit=crop&w=375&q=80" alt="">
</div>

<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541780050666-f64773a3d779?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=9ce82bea4ecf5b343e5317a683fd8226&auto=format&fit=crop&w=634&q=80" alt="">
</div>


<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541766029309-8d7fa5bb773b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f3d1bf633d2a601dd04a716acfce40be&auto=format&fit=crop&w=500&q=60" alt="">
</div>

</section>
</section>


scss



.grid
display: grid;
background-color: #fafafa;
max-width: 1300px;
clear: both;
margin: 0 auto;
grid-template-columns:1fr 1fr 1fr 1fr;
grid-auto-flow: dense;

grid-auto-rows: 100%;


.grid:after
content: '';
display: block;
clear: both;


.grid-item
display: flex;
position: relative;
overflow: hidden;
align-items:flex-start;
grid-column: auto / span 2;
grid-row: auto / span 4;



img
width: 100%;




.--width
grid-row: 2;



.--width2
grid-row: auto / span 4;










share|improve this question























  • Can you provide a codepen or a jsfiddle with the issue?
    – MartinBA
    Nov 11 at 2:35










  • ok, i updated it.
    – BARNOWL
    Nov 11 at 3:01










  • The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
    – Michael_B
    Nov 11 at 3:11






  • 1




    stackoverflow.com/q/44377343/3597276
    – Michael_B
    Nov 11 at 3:13







  • 1




    I commented the changes in the revised codepen. Also take a look at the link I posted.
    – Michael_B
    Nov 11 at 3:46












up vote
0
down vote

favorite









up vote
0
down vote

favorite











enter image description here



I'm trying to understand the nature of css grid, im somewhat new to it. I want to keep my grid items responsive and maintain the aspect ratio of the images. It seems that there is a weird gap on the bottom of the images.



I look at other questions that could be similar, still not sure.



here is what i have



https://codepen.io/eliowl/pen/EOgNQe



html



<section id="about" class="about">
<h3 class="text-center">About</h3>
<section class="grid">
<div class="grid-item --width3 ">
<img src="https://images.unsplash.com/photo-1541807084-5c52b6b3adef?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0c64fc542895cda41529f98ed3808572&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width ">
<img src="https://images.unsplash.com/photo-1541773477186-4133e93eb70e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=da73715faa685433b42f4decb9f71a60&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width2 ">
<img src="https://images.unsplash.com/photo-1541787975442-d5085a8ec678?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f6fc603cb3c4886ec55a1bff07ee7b53&auto=format&fit=crop&w=375&q=80" alt="">
</div>

<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541780050666-f64773a3d779?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=9ce82bea4ecf5b343e5317a683fd8226&auto=format&fit=crop&w=634&q=80" alt="">
</div>


<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541766029309-8d7fa5bb773b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f3d1bf633d2a601dd04a716acfce40be&auto=format&fit=crop&w=500&q=60" alt="">
</div>

</section>
</section>


scss



.grid
display: grid;
background-color: #fafafa;
max-width: 1300px;
clear: both;
margin: 0 auto;
grid-template-columns:1fr 1fr 1fr 1fr;
grid-auto-flow: dense;

grid-auto-rows: 100%;


.grid:after
content: '';
display: block;
clear: both;


.grid-item
display: flex;
position: relative;
overflow: hidden;
align-items:flex-start;
grid-column: auto / span 2;
grid-row: auto / span 4;



img
width: 100%;




.--width
grid-row: 2;



.--width2
grid-row: auto / span 4;










share|improve this question















enter image description here



I'm trying to understand the nature of css grid, im somewhat new to it. I want to keep my grid items responsive and maintain the aspect ratio of the images. It seems that there is a weird gap on the bottom of the images.



I look at other questions that could be similar, still not sure.



here is what i have



https://codepen.io/eliowl/pen/EOgNQe



html



<section id="about" class="about">
<h3 class="text-center">About</h3>
<section class="grid">
<div class="grid-item --width3 ">
<img src="https://images.unsplash.com/photo-1541807084-5c52b6b3adef?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0c64fc542895cda41529f98ed3808572&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width ">
<img src="https://images.unsplash.com/photo-1541773477186-4133e93eb70e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=da73715faa685433b42f4decb9f71a60&auto=format&fit=crop&w=634&q=80" alt="">
</div>

<div class="grid-item --width2 ">
<img src="https://images.unsplash.com/photo-1541787975442-d5085a8ec678?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f6fc603cb3c4886ec55a1bff07ee7b53&auto=format&fit=crop&w=375&q=80" alt="">
</div>

<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541780050666-f64773a3d779?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=9ce82bea4ecf5b343e5317a683fd8226&auto=format&fit=crop&w=634&q=80" alt="">
</div>


<div class="grid-item ">
<img src="https://images.unsplash.com/photo-1541766029309-8d7fa5bb773b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f3d1bf633d2a601dd04a716acfce40be&auto=format&fit=crop&w=500&q=60" alt="">
</div>

</section>
</section>


scss



.grid
display: grid;
background-color: #fafafa;
max-width: 1300px;
clear: both;
margin: 0 auto;
grid-template-columns:1fr 1fr 1fr 1fr;
grid-auto-flow: dense;

grid-auto-rows: 100%;


.grid:after
content: '';
display: block;
clear: both;


.grid-item
display: flex;
position: relative;
overflow: hidden;
align-items:flex-start;
grid-column: auto / span 2;
grid-row: auto / span 4;



img
width: 100%;




.--width
grid-row: 2;



.--width2
grid-row: auto / span 4;







html css css-grid






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 3:02

























asked Nov 11 at 2:02









BARNOWL

4611519




4611519











  • Can you provide a codepen or a jsfiddle with the issue?
    – MartinBA
    Nov 11 at 2:35










  • ok, i updated it.
    – BARNOWL
    Nov 11 at 3:01










  • The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
    – Michael_B
    Nov 11 at 3:11






  • 1




    stackoverflow.com/q/44377343/3597276
    – Michael_B
    Nov 11 at 3:13







  • 1




    I commented the changes in the revised codepen. Also take a look at the link I posted.
    – Michael_B
    Nov 11 at 3:46
















  • Can you provide a codepen or a jsfiddle with the issue?
    – MartinBA
    Nov 11 at 2:35










  • ok, i updated it.
    – BARNOWL
    Nov 11 at 3:01










  • The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
    – Michael_B
    Nov 11 at 3:11






  • 1




    stackoverflow.com/q/44377343/3597276
    – Michael_B
    Nov 11 at 3:13







  • 1




    I commented the changes in the revised codepen. Also take a look at the link I posted.
    – Michael_B
    Nov 11 at 3:46















Can you provide a codepen or a jsfiddle with the issue?
– MartinBA
Nov 11 at 2:35




Can you provide a codepen or a jsfiddle with the issue?
– MartinBA
Nov 11 at 2:35












ok, i updated it.
– BARNOWL
Nov 11 at 3:01




ok, i updated it.
– BARNOWL
Nov 11 at 3:01












The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
– Michael_B
Nov 11 at 3:11




The main problem is coming from align-items: flex-start. Remove that rule, and the gaps are gone. codepen.io/anon/pen/wQzoXo
– Michael_B
Nov 11 at 3:11




1




1




stackoverflow.com/q/44377343/3597276
– Michael_B
Nov 11 at 3:13





stackoverflow.com/q/44377343/3597276
– Michael_B
Nov 11 at 3:13





1




1




I commented the changes in the revised codepen. Also take a look at the link I posted.
– Michael_B
Nov 11 at 3:46




I commented the changes in the revised codepen. Also take a look at the link I posted.
– Michael_B
Nov 11 at 3:46

















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%2f53245215%2fcss-grid-empty-cell-issue%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















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245215%2fcss-grid-empty-cell-issue%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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto