弹性盒模型

更够更好的响应式布局。
例子

  • HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="CSS/normalize.css">
    <link rel="stylesheet" type="text/css" href="CSS/begin.css">
    <title>Title</title>
</head>
<body>
    <ul class="menu">
        <li><a href="#">one</a></li>
        <li><a href="#">two</a></li>
        <li><a href="#">three</a></li>
        <li><a href="#">four</a></li>
        <li><a href="#">five</a></li>
    </ul>
</body>
</html>

 

  • CSS:
.menu{
    list-style-type: none;
    padding0;
    margin0px;
    /*激活弹性布局*/
    display: flex;
    /*设置主轴方向以及是否换行*/
    flex-flow: row wrap;
}
.menu li{
    height40px;
    text-align: center;
    line-height40px;
    /*设置弹性子元素的空间分配*/
    /*最小情况下的弹性子元素布局*/
    flex1 1 100%;
}
.menu li a{
    color: white;
    text-decoration: none;
}
.menu li:nth-child(1){
    background-color: red;
}
.menu li:nth-child(2){
    background-color: orange;
}
.menu li:nth-child(3){
    background-color: yellow;
}
.menu li:nth-child(4){
    background-color: green;
}
.menu li:nth-child(5){
    background-color: purple;
}
/*进行媒体查询:为了判断设备*/
@media screen and (min-width: 480px){
    .menu li{
        flex1 1 50%;
    }
}
@media screen and (min-width: 768px) {
    .menu{
        flex-flow: row nowrap;
    }
}

 

  • 效果
    • 大于768px的时候
    • 480px<screen<768px
    • SCREEN<480px
posted @ 2018-09-26 20:25  Nnn_Lillian  阅读(168)  评论(0编辑  收藏  举报