im显示最大连续3张图像,如果您调整浏览器窗口的大小,它们会相互堆叠。
例如,现在,如果您调整窗口的大小并且仅显示一张图像,那么如何将图像的尺寸设置为width:100%;?
例如,我在https://www.slickwords.com/上看到了这一点。
我的代码:
#wrapper {
margin: 0 auto;
width: 900px;
max-width: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
div>div>div {
display: inline-block;
}
div>div {
text-align: center;
}
<div id="wrapper">
<div style="max-width:900px;margin: 0 auto;">
<div style="width:100%;">
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
<div><img src="img" width="250" height="150"><br>This text goes under the Picture.</div>
</div>
</div>
</div>
致谢
答案 0 :(得分:0)
您要查找的是 css媒体查询
这样简单的声明:
@media screen and (min-width: 992px) {
body {
background-color: blue;
}
}
您可以强制主体为蓝色(如果屏幕宽度大于992px)。
答案 1 :(得分:0)
您可以使用 flexbox 的flex-flow
属性并将min-width
应用于每个媒体查询,而不是使用媒体查询来手动测量图像堆积的位置。孩子们设定“断点”:
//The JS code here is just for fiddling around and isn't relevant.
let input = document.getElementById("setwidth");
input.onchange = e => {
document.getElementById("container").style.width = e.target.value+"%";
document.getElementById("widthspan").textContent = e.target.value+"%";
};
#container {
display: flex;
flex-flow: row wrap; /* This is where the magic happens!*/
align-items: flex-start;
align-content: flex-start;
justify-content: space-around;
border: 2px solid black;
}
#container>div {
flex-basis: 22.5%;
/*Try to take up 22.5% of the space, which would be almost a quarter but with a spacing of 2.5% total*/
background: blue;
border: 1px solid yellow;
height: 100px;
min-width: 80px;/* This is also where the magic happens */
}
<div id="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<!-- Just for fiddling around: -->
<hr>
Set container width: <span id="widthspan">100%</span>
<input id="setwidth" type="range" min="1" max="100" value="100"/>
其他资源:
答案 2 :(得分:0)
如蒂姆·格哈德(Tim Gerhard)上面建议的那样,您需要检查媒体查询。您也可以尝试以下方法。
我认为这些应该有效。