老师我有个问题
来源:3-17 编程练习
zhangwenxin
2020-05-14 12:46:23
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
/* 在此处补充代码*/
header{
display: flex;
background: black;
justify-content: space-around;
align-items: center;
}
.logo{
display: flex;
width: 200px;
}
.nav{
display: inline-flex;
color: white;
justify-content: space-between;
list-style: none;
align-items: center;
}
.nav li{
width: 100px;
align-items: center;
}
.login{
display: flex;
align-items: center;
}
input{
background-color: orange;
justify-content: space-between;
margin:0 20px;
border: none;
border-radius: 3px;
color: white;
}
section{
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.section{
background-color: #add8e6;
border-radius: 5px;
/* flex-grow: 1; */
width: 600px;
height: 200px;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
}
.box{
display: flex;
flex-direction: column;
justify-content: space-between;
}
.shopping{
width: 130px;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
background-color: #FFA500;
border-radius: 5px;
font-size: 20px;
font-weight: bold;
color: #fff;
}
.shopping:hover{
cursor: pointer;
color: #000;
}
</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>
</section>
</body>
</html>
我在给.box做flex布局的时候,.box有三个子元素,p/div/div,但是我发现在垂直排序的时候,使用justify-content:space-between只能让p和div变成两个部分,而不是三个部分,这是为什么呢?
1回答
好帮手慕慕子
2020-05-14
同学你好,因为.box盒子没有设置高度,所以设置了justify-content属性之后,效果实现有问题。建议:可以给box设置百分百填充满父元素,然后调整justify-content属性值,让效果实现更美观
代码中存在的其他问题解答如下:
1、练习要求主体部分有四个模块,建议再添加两个模块
使用百分比设置.section的宽度,添加下边距,设置盒子间距
在最外层盒子中添加flex-wrap属性,让其换行显示,实现两行两列显示效果。
2、如下所示,logo盒子没有包裹图片。
建议:去掉宽度,让其有图片撑开宽度,代码会更加规范
3、如下所示,由于列表有默认的左间距,导致整体水平居中存在误差
建议:使用通配符去除所有元素的默认间距
列表项设置固定宽度后,需要添加text-align:center;属性才可以让内容水平居中显示
4、如下所示,按钮效果实现不美观
建议优化:适当设置padding值,让效果实现更好
如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
相似问题