Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm a little embarrassed to admit that I've been working with this stuff for decades and I just now found out that margin and padding top is based on parent width if expressed in percentages. I'm only a little embarrassed because who expresses margins in percentages anyway.


You never needed to set some flexible containers dimensions to have some precise aspect ratio? Up until very recently [1] the "padding hack" used to be the only option…

https://css-tricks.com/aspect-ratio-boxes/

[1] Recently `aspect-ratio` got into evergreen browsers: https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-rati...


Exactly, I do this at least once a year, enough that I don't need to search anymore for the actual CSS (I just need to try two variations when I mix `padding-top: ratio%` or `padding-top 1/ratio%`)


Nope, never needed to do that. I've mostly only worked on some extremely unique use cases that use the browser in non-standard ways though (games, vehicle control, IDEs).


It sure is useful when hacking together “always-square”, responsive elements.

But otherwise you’re right, it doesn’t really come up.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: