手撕flex,向猛哥进阶:
先上代码:手动操作一次影响好深刻。
<style>
div{
margin: 100px;
background-color: #fde19a;
display: flex;
border: 1px solid #000;
/*flex-direction: row;*/
/*flex-direction: column;*/
/*flex-direction: column-reverse;*/
/*flex-direction: row-reverse;*/
/*flex-wrap: wrap;*/
/*flex-wrap: nowrap;*/
/*flex-wrap: wrap-reverse;*/
/* flex-flow:row wrap;*/
/*justify-content:flex-end;*/
/*justify-content:flex-start;*/
/*justify-content: center;*/
/*justify-content: space-around;*/
justify-content: space-between;
}
p{
border: 2px solid blue;
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
margin-left: 100px;
}
</style>
<body>
<div>
<p>王子</p>
<p>儿子</p>
<p>女儿</p>
<!-- <p>1</p>-->
<!-- <p>2</p>-->
<!-- <p>3</p>-->
<!-- <p>4</p>-->
<!-- <p>5</p>-->
<!-- <p>6</p>-->
<!-- <p>7</p>-->
<!-- <p>8</p>-->
</div>
flex-directioin:row
flex-directioin:row-reverse
flex-directioin:column-reverse,column
flex-wrap: wrap;
flex-wrap: nowrap;
flex-wrap: wrap-reverse; 第一行在下面
justify-content: flex-end
justify-content: flex-start
justify-content: center
justify-content: flex-around
justify-content: flex-between
<style>
div{
display: flex;
border: 1px solid #000;
height: 250px;
/*align-items: flex-start;*/
/*align-items: flex-end;*/
/*align-items: center;*/
align-items: baseline;
margin: 100px 300px 50px 300px;
}
p{
border: 1px solid red;
width: 80px;
text-align: center;
margin-left: 20px;
}
p:nth-child(1){
height: 80px;
line-height: 80px;
}
p:nth-child(2){
height: 160px;
}
p:nth-child(3){
height: 50px;
}
p:nth-child(4){
height: 100px;
}
</style>
<body>
<div>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
</div>
</body>
align-items:start
align-items:end
align-items:center
align-items:baseline
align-items:stretch p标签未设置高度的时候,会自动填充
align-content 属性同flex-content类似。