我试图像这样设计一个块:
图像应自动调整大小并占据整个宽度,直至到达红色块。
这是我的CSS:
#container {
background: yellow;
}
#floated {
float: right;
min-width: 200px;
max-width: 50%;
background: red;
}
#image {
width: 100%;
height: auto;
}
小提琴试试:
答案 0 :(得分:0)
将样式设置为img
以扭曲div
并设置width
#container {
width: 400px;
background: yellow;
}
#floated {
float: right;
width: 150px;
background: red;
}
img {
width: 240px;
height: auto;
}

<div id="container">
<div id="floated">float float float float float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float
floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float floatfloat float.</div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
<div id="iamge">
<img src="https://kbob.github.io/images/sample-1.jpg" />
</div>
<div>
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
&#13;
发表评论
@media screen and (min-device-width : 320px) and (max-device-width : 480px) {
img { width: 150px; }
}
了解media-query
:https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries