Live data from Hacker News

What does 100% mean in CSS? (2020)

wattenberger.com

71–72 of 72 posts

Re: What does 100% mean in CSS? (2020)

#71

Wait there are sooo many more edge cases of percentages! When this article finished I think it should be half way through or even one third of 100% weirdness. Examples: with flexbox and/or tables, 100% behaves differently. What about 100% vs 100vh/vw? This would be very nice to show here as well. As others note, background-position or background-size. Collapsing margins might be interesting, but probably not the best…

And that's just scratching the surface! There are all sorts of additional quirks, e.g. on mobile browsers the URL bar and the bottom bar (only on some OSs) will be ignored in the calculation, while the keyboard being toggled will not, which can cause all sorts of issues unless you combine it with viewport heights too: https://css-tricks.com/the-trick-to-viewport-units-on-mobile...

Re: What does 100% mean in CSS? (2020)

#72
post #7

Sadly the most interesting CSS percentage mechanic is missing there: background-position Unlike all other cases, here `background-position-x: [25]%` means: > "Place image so its inner left [quarter] boundary matches inner left [quarter] boundary of its container." So 0% = align left edges, 100% = align right edges, 50% = align centers (= center) etc. Super intuitive on the first sight, but I was quite surprised how t…

So it's equivalent to setting: left: x%; top: y%; transform: translate(-x%, -y%);

I use this all the time. One of the best ways to reliably center absolute elements.
Post reply on HN