html5 - 为什么设置 box-sizing 之后给子元素加 margin 会把父元素的 margin 也撑高?
黄舟
黄舟 2017-04-17 13:53:37
0
6
454
<style type="text/css">
        * {
            box-sizing: border-box;
        }
        
        #max-box {
            width: 500px;
            height: 500px;
            background-color: aliceblue;
            margin: 0 auto;
            /*position: relative;*/
            /*padding:   10px 10px;*/
        }
        
        #min-box {
            /*position: absolute;*/
            width: 300px;
            height: 300px;
            background-color: #4169E1;
            margin: 30px 100px 100px;
        }
    </style>

    <body>
        <p id="max-box">
            <p id="min-box">

            </p>
        </p>
    </body>

如图、我并没有给父元素 max-box 加 margin,但是也被撑高了

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(6)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!