Why can't the float element override the margin part of the sibling element?

sets the style to float:left for the block-level element, and the block-level sibling element has the style margin-top:30px . In this case, the floating element overrides its sibling element, but the floating element cannot overwrite the margin part of the sibling element.

the screenshot of the browser is as follows:

as you can see from the figure, the red floating element does not cover the margin part of the sibling element div-sharpwrap .

the style of each element is as follows:

-sharpbox {
    width: 200px; 
    height: 200px;
    padding-top: 20px;
    border-bottom: 10px solid;
    margin-bottom: 20px;
    background-color: red;
    float: left;
}

-sharpwrap {
    width: 100px;
    height: 100px;
    margin-top: 30px;
    background-color: yellow;
}
Css
Apr.11,2022

this is caused by margin overlap (or overlay).
'- sharpwrap' sets margin-top: 30pxshare wrap and body's margin-top overlay.
you can set border or padding for body, and then look at the effect, which is completely different.
is as follows:


can overwrite the margin part of the sibling element (the influence of body and other html code). Initialize the whole code first, or float the-sharpwrap part to achieve the effect you want.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b9cfd4-2f34a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b9cfd4-2f34a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?