老师,我的问题是本节的3-10编程练习。
来源:3-10 编程练习
慕斯0469344
2019-09-11 22:10:28
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
/*在此处补充代码*/
body{
margin:0;
padding:0;
}
header{
background-color: #000;
display: flex;
justify-content: space-around;
align-items: space-around;
}
.nav{
width: 30%;
display: flex;
justify-content: space-around;
align-content: space-around;
}
.nav{
color:#fff;
font-size: 18px;
list-style: none;
}
.login{
width: 20%;
display: flex;
justify-content: space-around;
align-items: center;
}
.login input{
width:80px;
height: 40px;
line-height: 40px;
border-radius: 5px;
font-size: 18px;
background-color: orange;
color:#fff;
border:none;
}
</style>
</head>
<body>
<header>
<div class="logo">
<img src="http://climg.mukewang.com/59feb59700019dab01910057.png" 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>
</body>
</html>老师,请问为什么在给nav,login设置flex布局的时候加上width才能保证项目之间有距离呢?
1回答
同学你好, 因为nav 和login如果不设置宽度, 默认宽度是由里面的子元素撑开的, 那就是刚好包裹子元素, 所以即使是flex布局, 项目之间也不会有间距, 只有设置宽度之后才能保证项目之间有距离
另, 对同一个元素元素设置样式, 可以写在一个选择下, 便于代码阅读哦

最后, 同学的代码效果实现的不错, 继续加油哦
如果帮助到了你, 欢迎采纳!
祝学习愉快~~~~~
相似问题
回答 1
回答 1
回答 1
回答 1