I am seeking a way to maintain the width of the .center
div in relation to its height, following a 4:3 aspect ratio (4 units wide for every 3 units high). The height of the div should be set to 100%
, and I also need to align the div horizontally at the center.
You can observe this effect on a website with a flash application, such as this one.
This is the current setup:
HTML:
<div id="stuff" class="center" width="800" height="600">
<canvas id="someHTML5">You cant play HTML5</canvas>
</div>
CSS:
.center {
position: absolute;
left: 50%;
width: 800px; /* I want to make this relative; ideally, it would be width: height/3*4 */
height: 100%;
margin-left: -400px; /* Adjusted for horizontal alignment */
z-index: 100;
}
In addition to the CSS styling, there is JavaScript code running to handle dynamic updates on the client side.