Just these 2:
grid-template-columns: 20% 20% 20% 20% 20%
grid-template-rows: 33% 33% 33%
Just these 2:
grid-template-columns: 20% 20% 20% 20% 20%
grid-template-rows: 33% 33% 33%
20% columns are 1/5th of the total width
And 33% rows are 1/3rd of the total height
You cannot always get full accuracy though when using pixel units
20% doesn’t look correct here:
Put it back to fractional units. Those are a recent CSS development purposely designed because of problems with percentage and pixel units.
Why is this wrong, look?
grid-template-columns: 50px 50px 50px 50px 50px;
Why is 50px not the right size?
Because math doesn’t work in that way.
What I’m looking at, nothing is uneven.
I’m serious about that too.
You have 5 boxes at 50 pixels = 250px
3px borders on each side (325) = 30px
4px gap between boxes (4*4) = 16px
250+30+16 adds up to more than 266 pixels.
Math doesn’t allow them to add up to 266 pixels or less.
The blue square boxes are 50px exact.
What I’m looking at, nothing is uneven.
You’re being too specific and failing to allow the web browser to take care of the details for you.
I gave you a good, reliable, and flexible solution before.
You are now experiencing pain from failing to use that solution.
Have you tried border-box yet
.nav a {
float: left;
box-sizing: border-box;
width: 50px;
height: 50px;
color: transparent;
background: blue;
}
Have you tried border-box yet
Does that work with grids?
I just did a live edit and it seemed to fix the bottom right box
My recommendation is to let the grid manage things for you.
.nav {
height: 100%;
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(3, 1fr);
grid-gap: 12px 4px;
}
Here:
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
And here too
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Look at mine:
Here:
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Look at mine:
The 50px width and height can be deleted along with the box-sizing, and everything still works perfect without them.
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Which, like you mentioned is the whole reason for letting the grid control it.
Border box can go too.
box-sizing: border-box;
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
.nav a {
float: left;
color: transparent;
background: rgba(0, 0, 0, .2);
border: 3px solid #0059dd;
}