精品免费在线观看-精品欧美-精品欧美成人bd高清在线观看-精品欧美高清不卡在线-精品欧美日韩一区二区

17站長網(wǎng)

17站長網(wǎng) 首頁 編程教程 CSS3教程 查看內(nèi)容

flex-direction 排列方向

flex-direction 排列方向

彈性和模型中內(nèi)部的子元素的排列方向可以通過這個屬性修改,那么我們就一起看下它的使用吧。

1. 官方定義

flex-direction 屬性規(guī)定項目的排列方向。

2. 解釋

flex-direction 用來調(diào)整主軸的方向,我們知道主軸默認是水平方向且從左到右,而我們可以通過這個屬性設置主軸的方向,即項目是水平方向從左到右還是垂直方向從上到下或者從下到上排列。

3. 語法

div{
    flex-direction: row|row-reverse|column|column-reverse|initial|inherit;
}
<div class="demo">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
</div>
.demo{
    display:flex; // 讓容器變成彈性盒
    flex-direction:row-reverse; 改變項目的排列方向
}

4. 兼容性

IEEdgeFirefoxChromeSafariOperaiosandroid
10+12+28+4+6.1+12.1+7+4.4

5. 實例

  1. 讓子元素從上到下垂直方向排列

.demo{
    display:flex; 
    flex-direction:column; 
    text-align: center;
    line-height: px;
}
.item{
    background:#ccc;
    height:px;
    border-bottom:px solid #fff;           
}

效果圖

編程之家

從上到下排列效果圖
<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo{
            display:flex; 
            flex-direction:column; 
            text-align: center;
            line-height: px;
        }
        .item{
            background:#ccc;
            height:px;
            border-bottom:px solid #fff;           
        }
    </style>
</head>
<body>
    <div class="demo">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</body>
</html>
  1. 讓子元素從下到上反向排列

.demo{
    display:flex; 
    flex-direction:column-reverse; 
    text-align: center;
    line-height: px;
}
.item{
    background:#ccc;
    height:px;
    border-bottom:px solid #fff;
}

效果圖

編程之家

從上到下反向排列效果圖
<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo{
            display:flex; 
            flex-direction:column-reverse; 
            text-align: center;
            line-height: px;
        }
        .item{
            background:#ccc;
            height:px;
            border-bottom:px solid #fff;           
        }
    </style>
</head>
<body>
    <div class="demo">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</body>
</html>
  1. 讓子元素從左到右排列

.demo{
    display:flex; 
    flex-direction:row; 
}
.item{
    background:#ccc;
    height:px;
    width: px;
    border-right:px solid #fff;           
}

效果圖

編程之家

從左到右排列效果圖
<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo{
            display:flex; 
            flex-direction:row; 
            text-align: center;
            line-height: px;
        }
        .item{
            background:#ccc;
            height:px;
            width: px;
            border-right:px solid #fff;           
        }
    </style>
</head>
<body>
    <div class="demo">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</body>
</html>
  1. 讓子元素從左到右反向排列

.demo{
    display:flex; 
    flex-direction:row-reverse; 
}
.item{
    background:#ccc;
    height:px;
    width: px;
    border-right:px solid #fff;           
}

效果圖

編程之家

從左到右反向排列效果圖
<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo{
            display:flex; 
            flex-direction:row-reverse; 
            text-align: center;
            line-height: px;
        }
        .item{
            background:#ccc;
            height:px;
            width: px;
            border-right:px solid #fff;           
        }
    </style>
</head>
<body>
    <div class="demo">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</body>
</html>

6. 經(jīng)驗分享

通過 flex 可以做一個上下固定,中間自適應的布局,它常常用于登錄頁那類的布局設置。

<div class="demo">
    <div class="head">頭部</div>
    <div class="content">內(nèi)容</div>
    <div class="foot">尾部</div>
</div>
html,body{
    padding:;
    margin:;
    height: ;
    color:#fff;
}
.demo{
    height: ;
    display: flex;
    flex-direction: column;
}
.head,.foot{
    
    flex:  px;
    background: #000;
}
.content{
    flex: ;
    background: red;
}

案例:

<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width, initial-scale=1.0">
    <Meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>demo</title>
    <style>
    html,body{
        padding:;
        margin:;
        height: ;
        color:#fff;
    }
    .demo{
        height: ;
        display: flex;
        flex-direction: column;
    }
    .head,.foot{
        
        flex:  px;
        background: #000;
    }
    .content{
        flex: ;
        background: red;
    } 
    </style>
</head>
<body>
<div class="demo">
    <div class="head">頭部</div>
    <div class="content">內(nèi)容</div>
    <div class="foot">尾部</div>
</div>
</body>
</html>

說明:這個布局就是兩端固定,中間自適應的典型寫法,而如果設置 flex-direction:row就變成了左右固定,中間自適應的橫向布局。而他們正是組成頁面的基礎。

7. 小結

  1. 一定要在彈性盒模型下使用。

  2. 可以通過樣式直接設置排列順序,節(jié)省瀏覽器性能。

返回頂部
主站蜘蛛池模板: 污网站大全免费 | 亚州一级毛片在线 | 国产精品欧美一区二区三区 | mm1313亚洲国产精品无 | 888午夜不卡理论久久 | 女人被狂躁的视频免费免费看 | 亚洲综合在线最大成人 | 国产精品无码2021在线观看 | 色天天综合网色鬼综合 | 伊人久久婷婷丁香六月综合基地 | 高清不卡日本v在线二区 | 国产日韩欧美二区 | 国产欧美亚洲精品 | 992tv快乐视频在线啪啪免费 | 色婷婷综合在线 | 色一情一乱一伦一区二区三区 | 国产精品亚洲第一区广西莫菁 | 色视频免费国产观看 | 亚洲欧美日韩一区超高清 | 国产日韩不卡免费精品视频 | 国产九色在线播放 | 麻豆91国语视频 | 嫩草视频在线观看 | 春水堂在线 | 涩涩快播 | 免费观看wwwwwww| 最刺激黄a大片免费观看 | 成人性爱视频在线观看 | 精品国产自在现线久久 | 欧美1区2区3区 | 亚洲瑟 | 91在线老王精品免费播放 | 亚洲欧美手机在线观看 | 免费一级视频在线播放 | 亚州精品一区二区三区 | 妞干网在线免费观看 | 丁香婷婷六月天 | 黄页成人免费网站 | 在线国产不卡 | 欧美乱码 | 成人午夜网 |