我知道这是个老问题,但我遇到了一个类似的问题做仅用CSS解决。这是我的博客帖子讨论解决方案。在这篇文章中包含了一个活例..代码转载如下。
HTML:
some text
CSS:#container {
display: inline-block;
position: relative;
width: 50%;}#dummy {
margin-top: 75%; /* 4:3 aspect ratio */}#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver /* show me! */}#container {
display: inline-block;
position: relative;
width: 50%;}#dummy {
margin-top: 75%;
/* 4:3 aspect ratio */}#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver/* show me! */}
some text