Why does the same CSS grid code give different layouts on different pages?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Why does the same CSS grid code give different layouts on different pages?



I have the exact same CSS on two pages (minus color changes) but the grid layout is responding differently on each. I tested adding more items and removing some, changing the grid-template-layout, and nothing has worked. I did copy and paste the exact code from the working page to the non-working page and it fixed the problem but I have gone through everything I could think of and there isn't anything I could find that should be making these two pages different.



What I want: 4 columns, same widths.



What I have: 1 page that does this. Other page has the first column large, second column medium, and last columns smaller. When you add columns the largest/medium/smaller column attributes change randomly to other columns.




.the-grid
padding-bottom: 20px;
max-width: 1640px;
margin: auto;


.the-grid-layout
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 60px;
-webkit-align-items: top;
-webkit-box-align: top;
-ms-flex-align: top;
align-items: top;
max-width: 1640px;
margin: 0 auto 120px;
position: relative;


.item
position: relative;


.image-cont
background-size: cover;
width: 100%;
height: 50px;
margin-bottom: 20px;
background-repeat: no-repeat;


.heading-cont
background-color: rgb(255, 255, 255);
text-align: center;
padding: 30px 20px;
transition: all 0.15s ease-in-out 0s;


<section class="the-grid">
<div class="the-grid-layout">
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
<div class="item">
<a href="/content-url">
<div class="image-cont" style="background-image:url(http://via.placeholder.com/350x150);"></div>
<div class="heading-cont">
<h5 class="heading">Item Title</h5>
</div>
</a>
</div>
</div>
</section>





the code you posted works as it should, it creates 4 even columns
– codeVerses
Aug 6 at 14:23





Is there maybe a longer content in one of the items in the layout that is broken.
– Domenik Reitzner
Aug 6 at 14:24





Indeed, you have to demo this the code NOT working as intended. You seem to indicate that you fixed the issue with a copy & paste which would indicate a typo somewhere,
– Paulie_D
Aug 6 at 14:25






I'm going to post the links here so you can see. Whatever you find I'll add to the question if there is a difference. Working: content.wearelel.com/critical/buy Not working: content.wearelel.com/semi/buy
– Cyberio
Aug 6 at 14:32





i see two layouts that are identical. Same width for the four columns. What is the issue exactly?
– Lelio Faieta
Aug 6 at 14:35




1 Answer
1



The problem with fr is that it takes the available space and will divide it as needed.


fr



If you want to have each part take up exactly 1/4 then use 25% instead of 1fr.


25%


1fr



Hope that helps.



PS: don't forget to subtract the gap.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard