In css, width, margin-left and margin-right are all set to specific values, and the total width of the horizontal part and the problem of over-limitation.

there are two points mentioned in the authoritative guide of 1.css: when the sum of the horizontal parts of the block-level element box in the normal flow is equal to the width;width, margin-left, and margin-right of the parent element are all set to specific values, these formatting attributes are too limited, and margin-right will always be cast to auto.
2. But what is observed in the actual chrome is not like this. We can see the box model of the child elements

clipboard.png
does not satisfy that the sum of the horizontal parts of the block-level element box in the normal flow is equal to the width, of the parent element and does not satisfy that width, margin-left, and margin-right are all set to specific values, margin-right will be forced to convert to auto.

3. The code is as follows:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title></title>
    </head>
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        .parent{
            width: 600px;
            background-color: red;
            border: 1px solid;
        }
        .children{
            height: 100px;
            width: 200px;
            margin: 100px;
            background-color: black;
        }
    </style>
    <body>
        <div class="parent">
            <div class="children"></div>
        </div>
    </body>
</html>

4. Is there something wrong with my understanding?

Css
Dec.05,2021

the width of your parent div is set to 320px and you'll see.
maybe you also need to take a look at the attribute box-sizing. Judging from the problems you describe, you have a lot of misunderstandings

.
Menu