更新时间:2016年04月18日14时25分 来源:传智播客UI培训学院 浏览次数:
<style type="text/css">
        *{
            margin:0;
            padding:0;
        }
        div{
            width: 400px;
            display: flex;
            margin:100px auto 0;
            border:1px solid #ccc;
        }
        p{
            height: 40px;
            width: 200px;
        }
        p:nth-child(1){
            background: lightblue;
        }
        p:nth-child(2){
            background: orange;
        }
        p:nth-child(3){
            background: seagreen;
        }
    </style>
</head>
<body>
    <div>
        <p></p>
        <p></p>
        <p></p>
</div>
可以设置相应的基数,如果子元素的基数和大于父元素总宽则需要收缩,如果小于就按着相应的比例扩展。
<html>
<head>
    <meta charset="UTF-8">
    <title>伸缩盒模型</title>
    <style type="text/css">
        *{
            margin:0;
            padding:0;
        }
        div{
            display: flex;
            width: 400px;
            margin:100px auto 0;
            border:1px solid #ccc;
        }
        p{
            width: 100px;
            height: 40px;
        }
        p:nth-child(1){
            background: lightblue;
        }
        p:nth-child(2){
            flex-grow: 1;
            background: orange;
        }
        p:nth-child(3){
            flex-grow: 4;
            background: seagreen;
        }
    </style>
</head>
<body>
    <div>
        <p></p>
        <p></p>
        <p></p>
    </div>
</body>
</html>