2 ms·
Q: How do you make a video maintain an aspect ratio and fill up the width of a parent? A: Nested div hell. Q: How do you make an image maintain an aspect ratio
by dheera 10y ago
Q: How do you make a video maintain an aspect ratio and fill up the width of a parent?
A: Nested div hell.
Q: How do you make an image maintain an aspect ratio and fill up the width or height of the screen, whichever comes first?
A: Nested div hell and JavaScript.
Q: How do you make a scaled background image stay put even when the keyboard input pops up on a phone?
A: Supreme JavaScript, CSS, and div hell.
Q: How do you center a paragraph of text vertically in a div?
A: Nested div hell.
I'd say FlexBox is pretty inadequate. Why can't we have things like:
#my-video {width:80%;height:calc(width*2/3);}
- pcwalton 10y agoCSS object-fit handles your first two complaints, and CSS Variables handles your last one.
- Dylan16807 10y agoAren't CSS Variables just constants you can reuse? How are they going to let you set width to 80% and height to 2/3 of whatever that ends up being?
- pcwalton 10y agoBecause percentages in heights are usually relative to the width of the containing block.