css3 利用dispaly:flex

直接上代碼:css

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
.t-r{
    display:flex;
    flex-direction: row;
    width: 200px;
    justify-content:center;
    border: 1px solid red;
    
}
.t-r div{
    border:1px solid blue;
    height: 60px;
}

.t-c{
    display: flex;
    flex-direction: column;
    width:200px;
    align-items:center;
    border: 1px solid red;
}
.t-c div{
    border:1px solid blue;
    width: 100px;
}
</style>
</head>
<body>
<div class="t-r">
<div>123</div>
<div>456</div>
<div>789</div>
</div>
<div class="t-c">
<div>123</div>
<div>456</div>
<div>789</div>
</div>
</body>
</html>

效果如圖:html

設爲Flex佈局之後,子元素的floatclearvertical-align屬性將失效。佈局

主要列出我本身經常使用的特性,更多佈局請參考:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicoolflex

相關文章
相關標籤/搜索