猿问

请问大神,用css写的瀑布流,没有设置宽度,为什么子元素的宽度都是100px?


<style>.box{margin:0px auto;border:5px solid pink;}/*只有div有宽度时margin—auto才有效果*/

.box div{float:left;width:100px;}

.left{background:red;}

.left div{height:150px;border:1px solid #fff;}

.center{background:green;}

.center div{height:100px;border:1px solid #fff;}

.right{background:yellow;}

.right div{height:150px;border:1px solid #fff;}

.clearfix:after{content:"";display:block;clear:both;height:0;}

</style>

</head>


<body>

<div class="box clearfix">

<div class="left">

    <div></div>

        <div></div>

    </div>

    <div class="center">

    <div></div>

        <div></div>

        <div></div>

    </div>

    <div class="right">

    <div></div>

        <div></div>

    </div>

</div>

</body>

<style>.box{margin:0px auto;border:5px solid pink;}/*只有div有宽度时margin—auto才有效果*/

.box div{float:left;width:100px;}

.left{background:red;}

.left div{height:150px;border:1px solid #fff;}

.center{background:green;}

.center div{height:100px;border:1px solid #fff;}

.right{background:yellow;}

.right div{height:150px;border:1px solid #fff;}

.clearfix:after{content:"";display:block;clear:both;height:0;}

</style>

</head>

<body>

<div class="box clearfix">

<div class="left">

    <div></div>

        <div></div>

    </div>

    <div class="center">

    <div></div>

        <div></div>

        <div></div>

    </div>

    <div class="right">

    <div></div>

        <div></div>

    </div>

</div>

</body>

极爷3964486
浏览 1771回答 1
1回答

极爷3964486

代码中有对所有子元素设置的样式,在下小了眼了。唉
随时随地看视频慕课网APP
我要回答