What I have is a standard form in HTML that allows the user to select a “Width” option and a “Height” option (each with values ranging from 1 to 10). When they send the form, it sends it to a PHP/HTML page where PHP grabs the “Width” and “Height” variables and assigns it to a width and height of a DIV.
But what I’m trying to do is just use the “Width” and “Height” variables to assign an aspect ratio to that DIV, and then have that DIV auto-resize to 100% of the container it is inside, but while keeping that same aspect ratio.
Example:
User selects a Width of 4 and a Height of 2, then sends the form. On the receiving PHP page, that DIV (the one receiving the width and height ratios) is inside a container that’s 1000px width and 600px height. So now, that DIV resizes to 1000px wide and 500px tall (that would be the aspect ratio of 4 to 2)
Any ideas, codes, scripts would be extremely helpful, thank you very much!
Aaron
Since percentage values of the
padding-*properties are calculated with respect to the width of the generated box’s containing block, you could:padding-toporpadding-bottom), corresponding to the desired aspect ratio.This idea is taken from http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio
Note vertical margin could be used instead of vertical padding, but then there would be margin collapse. To prevent it, add
Using
::beforepseudo element, there’s no need to use a dummy element: