https://stackoverflow.com/questions/5445491/height-equal-to-dynamic-width-css-fluid-layout
- html
<div id="container">
<div id="dummy"></div>
<div id="element">
some text
</div>
</div>
- css
#container {
display: inline-block;
position: relative;
width: 100%;
}
#dummy {
margin-top: 50%;
}
#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver;
}
网友评论