I might be going pixel-crazy, but when I'm working on front-end design, I like things to be accurate. Let's say I have 3 squares in a container element, with exactly the same HTML markup:
<div class="page">
<div class="active"></div>
</div>
They all have the same style. The one of the middle is not the exactly same than the others. It misses some padding pixels on the sides.
Can someone tell me why? Is there a way to make it work? I encounter the problem on Chrome (last version). On Firefox, none of them are alike. It's a shame but it only works as expected on IE11.
Code (JSFiddle):
body {
background-color: #222;
}
.navigator {
position: absolute;
bottom: 20px;
}
.page {
border: 1px solid #3cbeff;
box-sizing: border-box;
display: inline-block;
height: 15px;
margin: 5px;
width: 15px;
padding: 2px;
}
.page>div {
opacity: 0;
transition: opacity 0.5s ease;
}
.page>div.active {
animation-name: active;
animation-direction: alternate;
animation-duration: 1s;
animation-iteration-count: infinite;
height: 100%;
opacity: 1;
}
@keyframes active {
from {
background-color: #3cbeff;
}
to {
background-color: white;
}
}
<div class="navigator">
<div class="page">
<div class="active"></div>
</div>
<div class="page">
<div class="active"></div>
</div>
<div class="page">
<div class="active"></div>
</div>
</div>
Here is what I got on my screen. For Chrome and Firefox:
With @KarelIG solution (JSFiddle):
body {
background-color: #222;
}
.navigator {
position: absolute;
bottom: 20px;
}
.page {
border: 1px solid #3cbeff;
display: inline-block;
height: 15px;
margin: 5px;
width: 15px;
padding: 0.2em;
}
.page>div {
opacity: 0;
transition: opacity 0.5s ease;
}
.page>div.active {
animation-name: active;
animation-direction: alternate;
animation-duration: 1s;
animation-iteration-count: infinite;
height: 100%;
opacity: 1;
}
@keyframes active {
from {
background-color: #3cbeff;
}
to {
background-color: white;
}
}
<div class="navigator">
<div class="page">
<div class="active"></div>
</div>
<div class="page">
<div class="active"></div>
</div>
<div class="page">
<div class="active"></div>
</div>
</div>
I got this:
To me, the first square is slightly different from the others. On the two others, the side padding is 1px
less than the top/bottom padding.
EDIT
It is definitely a subpixel rendering problem.
I guess I cannot help it: even if everything is in px in my CSS, I obviously have to center one element or another, and I cannot guarantee it'll fit every hardware pixel grid.
I saw that it was the problem by moving the squares: according to their position and margin between each other, the square would change and eventually not be square.
I assume I should just let it go as it is! Except if someone has another idea, but I didn't find any clean solution that will work for every browser to solve that kind of problem so far.