12
我知道有可能specify an element's height relative to its width,因爲百分比邊距和填充值是相對於其寬度計算的。是否有可能做相反的寬度相對於高度?使元素的寬度相對於其高度?
我知道有可能specify an element's height relative to its width,因爲百分比邊距和填充值是相對於其寬度計算的。是否有可能做相反的寬度相對於高度?使元素的寬度相對於其高度?
我找到了一種不使用Javascript的方法。用比例製作圖像,並將其嵌入到HTML中,然後相應地縮放,以便父元素可以適合圖像大小。
<!-- height of the outer container -->
<div style="height: 200px">
<!-- this will resize to 200px and maintain its aspect ratio --->
<div style="display: inline-block; position: relative;">
<img src="aspectratio.png" style="height: 100%; width: auto;" />
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0">
<!-- Everything in here can party on the fact that their parent
has the correct aspect ratio -->
</div>
</div>
</div>
是否可以裁剪img從而產生任意長寬比? – mulllhausen
@mulllhausen你可以使用帶有'visibility:hidden'的http://placekitten.com/圖片。 – Brilliand