老师 section不设置高的话 就会出现截图的情况 实际开发中应该不会把高度设死吧 那我的问题在哪里?
来源:3-17 编程练习
weixin_慕莱坞5016066
2021-04-15 23:03:31
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
header{
display: flex;
background-color: black;
justify-content: space-around;
align-items: center;
}
.nav{
display: flex;
list-style: none;
color: white;
justify-content: space-between;
font-size: 25px;
width: 40%;
}
.login{
width: 10%;
display: flex;
justify-content: space-between;
}
.login input{
background-color: orange;
font-size: 20px;
border: none;
color: white;
border-radius: 3px;
}
section{
display: flex;
flex-wrap: wrap;
/* height: 500px; */
justify-content:space-around;
align-content: space-around;
}
.section{
height: 200px;
width: 45%;
background-color: blue;
border-radius: 5px;
display: flex;
justify-content: space-around;
}
.section .box{
display: flex;
flex-direction: column;
justify-content: space-around;
}
.section .shopping{
height: 18%;
width: 20%;
display: flex;
background-color: orange;
color: white;
border-radius: 3px;
align-self: center;
justify-content: space-around;
align-items: center;
}
</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>
</body>
</html>
相关截图:
1回答
好帮手慕久久
2021-04-16
同学你好,解答如下:
1、如果section中的内容是固定,那么就可以给section设置固定高。反之,section中的.section个数不确定,那么就不能设置固定高。
2、如果想让.section上下之间有间距,可以使用margin、padding来调整,如下:
代码可做如下优化:
按钮文字紧挨父元素边缘,样式不好看,可以使用padding调整一下:
除此之外,代码没有其他问题。
祝学习愉快!
相似问题