CSS Flex align-self 控制子元素的位置
2020-01-01 本文已影响0人
GaoEnron
通过:align-self: 控制子元素位置
// article下面的首个div元素拉伸效果
article :first-child {
align-self: stretch;
height: auto;
}
通过:align-self: flex-start 控制子元素位置辅轴其实位置
// article下面的首个div元素
article :first-child {
align-self: flex-start;
}
Jietu20200101-153333.jpg
测试代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" content="width=device-width, initial-scale=1.0">
<title></title>
<style type="text/css">
* {
padding: 0px;
margin: 0px;
}
body {
padding-left: 0px;
padding-top: 15px;
}
article {
display: flex;
border: solid 5px silver;
border-color: #8A2BE2;
width: 550px;
height: 500px;
background: red; /* */
flex-direction: row;
align-items: flex-end;
}
article * {
width: 100px;
height: 100px;
}
article :first-child {
align-self: stretch;
height: auto;
}
.first {
background: #87CEEB;
}
.second {
background: #FFA07A;
}
.third {
background: lightpink;
}
.fourth {
background: lightgreen;
}
</style>
</head>
<body>
<article>
<div class="first">第一</div>
<div class="second">第二</div>
<div class="third">第三</div>
<div class="fourth">第四</div>
<div class="third">第三</div>
<div class="fourth">第四</div>
</article>
</body>
</html>