The problem that the CSS element does not set the width?

< H1 > box1 {< / H1 >
height:100px;
padding:100px;
background-color:black;

}

< H1 > box2 {< / H1 >
height:100px;
margin: 0 -100px;
background-color:black;

}

what is the principle that neither of the above box sets the width, but can be stretched to the width of the entire browser?

Jun.21,2022

Block element does not set width, which defaults to 100% of parent element width


Block element width occupies full parent element width by default in standard document stream


Block element default width

Menu