
批改狀態(tài):合格
老師批語:你的手寫部分, 猶如印刷體, 人肉打字機(jī)呀, 作業(yè)完成的相當(dāng)棒, 超出預(yù)期
Flex是Flexible Box的縮寫,意為”彈性布局”,用來為盒狀模型提供最大的靈活性。
任何一個(gè)容器都可以指定為Flex布局
.box{
display:flex;
}
行內(nèi)元素也可以使用Flex布局。
.box{
display:inline-flex;
}
Webkit內(nèi)核的瀏覽器(safari),必須加上-webkit前綴。
.box{
display: -webkit-flex;
display: flex;
}
采用Flex布局的元素,稱為Flex容器(flex container),簡稱”容器”。它的所有子元素自動(dòng)成為容器成員,稱為Flex項(xiàng)目(flex item),簡稱”項(xiàng)目”。
--flex-direction:
row:(默認(rèn))主軸為水平方向,起點(diǎn)在左端
row-reverse:主軸為水平方向,起點(diǎn)在右端。
column:主軸為垂直方向,起點(diǎn)在上方。
columu-reverse:主軸為垂直方向,起點(diǎn)在下方。
運(yùn)行實(shí)例:
<style>
.box{
width: 800px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-direction: row;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
<style>
.box{
width: 800px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-direction: row-reverse;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
</div>
<style>
.box{
width: 800px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-direction: column;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
</div>
</body>
<style>
.box{
width: 800px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-direction: column-reverse;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
</div>
</body>
<style>
.box{
width: 800px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-wrap:nowrap;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
</div>
</body>
<style>
.box{
width: 850px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-wrap:wrap;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
</div>
</body>
<style>
.box{
width: 850px;
height: 300px;
background-color: antiquewhite;
border-style:solid;
margin:auto;
display: flex;
/*適配 safari 瀏覽器*/
display: -webkit-flex;
flex-wrap:wrap-reverse;
}
p{
width: 160px;
height: 80px;
background-color: aqua;
border-style:dashed ;
font-size:25px;
}
</style>
</head>
<body>
<div class="box">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
</div>
</body>
該屬性定義了多根軸線的對齊方式。如果項(xiàng)目只有一根軸線,該屬性不起作用
flex-start:與交叉軸的起點(diǎn)對齊。
flex-end:與交叉軸的終點(diǎn)對齊。
center:與交叉軸的中點(diǎn)對齊。
space-between:與交叉軸兩端對齊,軸線之間的間隔平均分布。
space-around:每根軸線兩側(cè)的間隔都相等。所以,軸線之間的間隔比軸線與邊框的間隔大一倍。
stretch(默認(rèn)值):軸線占滿整個(gè)交叉軸。
手寫屬性:
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)