【发布时间】:2017-04-01 11:16:16
【问题描述】:
我正在尝试将现有设计转换为(有点)响应式布局。 它在左上角有一个浮动框(蓝色框),其余内容应该浮动(文本和绿色框,代表图像)。
我正在寻找一种方法来调整图像(绿色框)的大小,只要它位于浮动的蓝色框旁边,但在被其他内容(lorem ipsum)推到它下方时恢复正常大小.
我通常的做法是说max-width:100%,但由于蓝框,这不会在这里起作用。
我已经有一种方法(fiddle,与下面的 sn-p 相同)使用包装 div,它演示了所需的行为,但这意味着将每个内容图像包装在一个 div 中。
在没有包装 div 的情况下,还有其他聪明的方法吗?
/* try varying the width of #wrap to see the effect */
#wrap {
border:1px solid #aaa;
min-height:200px;
width:280px;
background-color:#ddd;
padding:10px;
}
#blue {
width:150px;
height:100px;
border:1px solid #aaa;
float:left;
background-color:#ccccff;
overflow:hidden;
margin-right:10px;
}
#green {
min-width:100px;
min-height:30px;
background-color:#ccffcc;
border:1px solid #aaa;
overflow:hidden;
max-width:100%;
}
#green > img {
width:100%;
}
<div id="wrap">
<div id="blue"></div>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr.
<div id="green"><img src="http://lorempixel.com/400/200/"/></div>
</div>
【问题讨论】:
标签: html css responsive-design