老师,我的代码中,为什么缩小屏幕,section项目不会缩小,最终垂直排列了
来源:3-19 媒体查询-基础(2)
saltedfishman
2020-10-29 16:34:06
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
@media screen and (min-width: 1200px)and (max-width: 2000px) {
body {
background: green;
}
}
header {
color: white;
background-color: black;
display: flex;
justify-content: space-around;
}
header .nav {
display: flex;
align-items: center;
width: 400px;
justify-content: space-between;
font-size: 30px;
}
header .login {
width: 150px;
display: flex;
align-items: center;
justify-content: space-between;
}
header .login input {
width: 60px;
height: 35px;
background-color: orange;
border-radius: 5px;
border: none;
font-size: 20px;
color: white;
}
section {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-content: space-around;
height: 300px;
background-color: gray;
}
section .section {
background-color: skyblue;
width: 425px;
height: 110px;
border-radius: 10px;
display: flex;
justify-content: space-around;
align-items: center;
font-weight: bold;
}
section .section .box {
font-size: 15px;
line-height: 25px;
}
section .section .shopping {
background-color: orange;
width: 120px;
height: 60px;
font-size: 20px;
line-height: 60px;
text-align: center;
color: white;
font-weight: bold;
border-radius: 12px;
}
</style>
</head>
<body>
<!-- 头部 -->
<header>
<div class="logo">
<img src="http://climg.mukewang.com/59197ab000014f1503000100.jpg" alt="">
</div>
<ul class="nav">
<li>课程</li>
<li>路径</li>
<li>猿问</li>
<li>手记</li>
</ul>
<div class="login">
<input type="button" value="登录">
<input type="button" value="注册">
</div>
</header>
<!-- 主体内容 -->
<section>
<div class="section">
<div class="box">
<p>《前端小白入门手册》</p>
<div>适用人群:没有任何前端基础的小白</div>
<div>费用:¥499</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
<div class="section">
<div class="box">
<p>《HTML5月CSS3实现动态网页》</p>
<div>适用人群:有html和css基础的童鞋</div>
<div>费用:¥599</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
<div class="section">
<div class="box">
<p>《HTML5月CSS3实现动态网页》</p>
<div>适用人群:有html和css基础的童鞋</div>
<div>费用:¥599</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
<div class="section">
<div class="box">
<p>《HTML5月CSS3实现动态网页》</p>
<div>适用人群:有html和css基础的童鞋</div>
<div>费用:¥599</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
</section>
<script>
</script>
</body>
</html>
在这里输入代码,可通过选择【代码语言】突出显示
1回答
同学你好,出现问题的原因是:section容器设置的固定的宽度,当一行的宽度排不下两个section容器的时候,就变成了垂直效果,建议给section设置百分比的宽度,例如40%。
建议同学给body设置一个最小宽度,当浏览器缩小到这个宽度的时候,页面内容就不再发生改变,参考如下:
祝学习愉快!
相似问题