学习记录
参考资料
练习
- 实现下面的效果
思路一
思路描述: 整体是一个大盒子(parent),采用flex布局 一共三个子盒子(line),设置一下宽度和高度,用
flex-wrap使得换行
代码如下:
<style>
*{
margin:0;
padding: 0;
}
.parent{
width: 100%;
height: 400px;
background-color: aqua;
display: flex;
flex-wrap: wrap;
}
.item{
width: 50px;
height: 50px;
border-radius: 50%;
background-color:chartreuse;
}
.line{
background-color: red;
margin-top:1%;
padding-top: 10%;
width: 100%;
height: 100px;
display: flex;
justify-content: space-around;
}
</style>
<body>
<div class="parent">
<div class="line">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="line">
<div class="item"></div>
</div>
<div class="line">
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</body>
</html>
思路二
我这里出了点问题
思路三
五个全部放在一行,然后用绝对定位来定位,由于我css相关的东西忘记了 好像是父容器是相对定位,子容器是绝对定位
<!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;
}
.parent{
padding:40px;
border: 4px solid burlywood;
width: 800px;
height: 600px;
display: flex;
justify-content: space-between;
position: relative;
}
.child{
height: 100px;
width: 100px;
border-radius: 50%;
background-color: aquamarine;
}
.child3{
align-self: center;
}
.child2{
left: 0;
bottom: 0;
position: absolute;
left:40px;
}
.child5{
/* left: 0; */
bottom: 0;
position: absolute;
right:40px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child child1"></div>
<div class="child child2"></div>
<div class="child child3"></div>
<div class="child child4"></div>
<div class="child child5"></div>
</div>
</body>
</html>
学到的东西
- css布局,父容器是相对定位,子容器是绝对定位
- align-self:若有父容器则继承父容器的align-items,默认值是strectch,我个人用的感觉是可以控制单个元素的位置