图片还是不能随屏幕的变化而变化?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<!-- <meta name=""> -->
<style>
#box{
width:80%;
margin:0 auto;
background: #ccc;
text-align:center;
}
#box>img{
display: inline-block;
padding:1.5%;
width:21%;
height:200px;
}
/*此处写代码*/
#box{
display:flex;
flex-wrap:wrap;
}
@media screen and (min-width:960px){
img{
width:100%;
}
}
@media screen and (min-width:780px)and{max-width:961px}{
img{
width:100%;
}
}
@media screen and (min-width:440px)and{max-width:801px}{
img{
width:100%;
}
}
@media screen and{max-width:441px}{
img{
width:100%;
}
}
</style>
</head>
<body>
<div id="box">
<img src="http://img1.sycdn.imooc.com//climg/5a45e49100014e5010601059.jpg" alt="">
<img src="http://img1.sycdn.imooc.com//climg/5a45e53b00012e6d09940789.jpg" alt="">
<img src="http://img1.sycdn.imooc.com//climg/5a45e53c0001d04e09940732.jpg" alt="">
<img src="http://img1.sycdn.imooc.com//climg/5a45e49100014e5010601059.jpg" alt="">
<img src="http://img1.sycdn.imooc.com//climg/5a45e53b00012e6d09940789.jpg" alt="">
<img src="http://img1.sycdn.imooc.com//climg/5a45e53c0001d04e09940732.jpg" alt="">
</div>
</body>
</html>
正在回答 回答被采纳积分+1
同学你好,代码中的问题:
1、宽度条件要用()表示,不是{}哦:
2、不需要使用flex布局,使用媒体查询控制图片的宽度即可。
3、图片的选择器要使用之前的#box>img,否则只使用img是覆盖不了之前设置的样式的,选择器权重不够。
可以参考下面修改的:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <!-- <meta name=""> --> <style> #box { width: 80%; margin: 0 auto; background: #ccc; text-align: center; } #box>img { display: inline-block; padding: 1.5%; width: 21%; height: 200px; } /*此处写代码*/ /* #box { display: flex; flex-wrap: wrap; }*/ @media screen and (min-width:960px) { #box>img { width: 21%; } } @media screen and (min-width:780px) and (max-width: 961px) { #box>img { width: 29%; } } @media screen and (min-width:440px) and (max-width: 780px) { #box>img { width: 46%; } } @media screen and (max-width: 440px) { #box>img { width: 100%; } } </style> </head> <body> <div id="box"> <img src="http://img1.sycdn.imooc.com//climg/5a45e49100014e5010601059.jpg" alt=""> <img src="http://img1.sycdn.imooc.com//climg/5a45e53b00012e6d09940789.jpg" alt=""> <img src="http://img1.sycdn.imooc.com//climg/5a45e53c0001d04e09940732.jpg" alt=""> <img src="http://img1.sycdn.imooc.com//climg/5a45e49100014e5010601059.jpg" alt=""> <img src="http://img1.sycdn.imooc.com//climg/5a45e53b00012e6d09940789.jpg" alt=""> <img src="http://img1.sycdn.imooc.com//climg/5a45e53c0001d04e09940732.jpg" alt=""> </div> </body> </html>
祝学习愉快!
- 参与学习 人
- 提交作业 622 份
- 解答问题 6815 个
微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星