No more pixel rounding issues!
One line of code that looks strange and confusing. You may think it's not even CSS but it will save you many times in the future:
.container {
width: calc-size(auto,round(down,size,1px));
/* works with height as well */
}
It will make sure the width of your element is always an integer! No more decimal and rounding issues!
The behavior of width:auto
with an upgrade.
No browser support yet but you can test it on the latest Chrome with the experimental flag enabled:
See the Pen width: auto with pixel rounding by Temani Afif (@t_afif) on CodePen.
If you are explicitly setting a size you can use the following which is widely supported:
.container {
width: round(down,X,1px); /* instead of width: X */
/* X can be anything (100%,10rem,50vw,45cqi, etc) */
}
More CSS Tips
- Custom range slider with tooltip II Using modern CSS features to create a fancy range slider with tooltop.
- Better text wrapping using text-wrap The text-wrap property allows you to control how text is wrapped.
- Single-digit inputs with one element (OTP) Turn a simple input into an One Time Password field.
- A Sparkle shape with one gradient Create a fancy sparkle shape using only one gradient.