Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Flexible Box Model and Fixed Aspect Ratio

Tags:

css

All the examples I could find of flexible box model show stuff expanding either in the horizontal direction or the vertical direction. I could not find out how to let things flexibly expand while maintaining a fixed aspect ratio.

like image 612
user782220 Avatar asked Jul 20 '11 06:07

user782220


People also ask

Is it possible to have a responsive div with fixed aspect ratio?

In the HTML, put the player <iframe> in a <div> container. In the CSS for the <div>, add a percentage value for padding-bottom and set the position to relative, this will maintain the aspect ratio of the container. The value of the padding determines the aspect ratio. ie 56.25% = 16:9.

Is css3 flexible box layout using which way to arrange elements?

In the flex layout model, the children of a flex container can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated.

What is 50% Flex CSS?

flex-basis defines the default size of an element before the remaining space is distributed. So in this case, you have defined all a children` to 50%.


1 Answers

I asked a similar question recently in a W3C course forum, and got an in-depth reply from one of the instructors, Phil Archer. He suggests using SVG to maintain aspect ratio while scaling, and also shows by example that it works well in web browsers, but not so well on mobiles. See http://philarcher.org/diary/2012/scalablesquares for more info.

like image 58
Per Quested Aronsson Avatar answered Sep 21 '22 10:09

Per Quested Aronsson