栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

根据高度保持div长宽比

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

根据高度保持div长宽比

您可以使用具有所需比例的图像来帮助按比例调整大小(可以通过将一维设置为某个值,另一维设置为“自动”来按比例缩放图像)。图像不必是可见的,但必须占用空间。

.box {  position: absolute;  bottom: 0;  left: 0;  height: 50%;}.size-helper {  display: block;  width: auto;  height: 100%;}.inner {  position: absolute;  top: 0;  bottom: 0;  left: 0;  right: 0;  background: rgba(255, 255, 153, .8);}<div >  <img  src="https://www.mshxw.com/skin/sinaskin/image/nopic.gif" width="200" height="100">  <div >    1. box has fluid height<br>    2. img has 2:1 aspect ratio, 100% height, auto width, static position<br>    2.1 it thus maintains width = 200% of height<br>    2.2 it defines the dimensions of the box<br>    3. inner expands as much as box  </div></div>

在上面的示例中,box,inner和helper的大小都相同。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/420881.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号