HTML two box models

Box model 1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #one{
            height: 100px;
            width: 200px;
            background: green;
        }
        #a{
            width: 50%;
            height: 100%;
            background: blue;
            float: left;
        }
        #b{
            width: 50%;
            height: 100%;
            background: gray;
            float: right;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div id="one">
        <div id="a"></div>
        <div id="b"></div>
    </div>
</body>
</html>

Insert picture description here
The above is the new box model. If paddingborder is added, the parent div will not be able to accommodate these added new attributes and expand outward.

Box model 2
If we convert the above box model into an old-fashioned IE browser and store it inside, we only need to add the following CSS code to change the properties of the box model

 box-sizing: border-box; 
 box-sizing: border-box ;

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41526316/article/details/89764079