高度等于动态宽度(CSS流体布局)是否可以设置与宽度相同的高度(1:1)?例+----------+| body || 1:3 || || +------+ || | div | || | 1:1 | || +------+ || || || || || |+----------+CSSdiv { width: 80%; height: same-as-width}
3 回答
狐的传说
TA贡献1804条经验 获得超3个赞
<div id="container"> <div id="dummy"></div> <div id="element"> some text </div></div>
#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! */}
<div id="container"> <div id="dummy"></div> <div id="element"> some text </div></div>
添加回答
举报
0/150
提交
取消