老师这样对吗?section的高度和.section的高度时需要自己设定吗?
来源:3-17 编程练习
我不是胖球球
2021-09-02 22:43:56
相关代码:实际开发中也是将高度设死吗?总感觉不太对,.section的宽度也是自己调出来的,也感觉不太对
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
/* 在此处补充代码*/
* {
margin: 0;
padding: 0;
}
/* 三大容器(logo、导航项、按钮)在一行显示,并且要垂直居中。 */
header {
display: flex;
margin: 0 auto;
background-color: rgba(5, 5, 5, 0.986);
/* 主轴上的对齐方式,两侧间隔相等 */
justify-content: space-around;
/* 交叉轴上中点对齐 */
align-items: center;
}
/* 对容器进行弹性布局(导航项容器和按钮也要使用弹性布局) */
.logo,
.nav,
.login {
display: flex;
}
.logo img {
display: block;
}
/* 导航项之间的距离要相等 */
.nav li {
list-style: none;
line-height: 60px;
height: 60px;
width: 100px;
text-align: center;
color: white;
}
.login input {
border: none;
margin-right: 20px;
background-color: rgb(250, 185, 5);
color: white;
padding: 5px 10px;
border-radius: 4px;
}
.login input:last-child {
margin-right: 0px;
}
section {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
height: 400px;
align-content: space-around;
justify-content: space-around;
}
section .section {
background-color: rgb(12, 156, 252);
display: flex;
width: 45%;
height: 160px;
border-radius: 3px;
justify-content: space-around;
align-items: center;
}
section .section .box{
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
section .section .shopping{
display: flex;
align-items: center;
}
section .section .shopping .btn{
color: white;
font-size: 18px;
padding: 2px 5px;
border-radius: 5px;
background-color: rgb(255, 197, 6);
}
</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>《从H5响应开发到移动端flex开发》</p>
<div>适用人群:有html、css、js、jQ基础的童鞋</div>
<div>费用:¥599</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
<div class="section">
<div class="box">
<p>《从H5响应开发到移动端flex开发》</p>
<div>适用人群:有html、css、js、jQ基础的童鞋</div>
<div>费用:¥599</div>
</div>
<div class="shopping">
<div class="btn">加入购物车</div>
</div>
</div>
</section>
</body>
</html>
1回答
同学你好,代码实现效果可以。
针对提问回复:
section和.section可以设置固定高度,看着美观即可。实际开发中一般设计稿上会给出高度的,按照标注的来写即可。
如果不想给section设置高度,可以去掉,然后给.section设置上外间距,例如
祝学习愉快!
相似问题