The Impact of Using inline-block on Behavior
Here is the original CSS code:
#DivHeader
{
position:relative;
display:inline-block;
width:100%;
font-family: Century Gothic, sans-serif;
background-color:#3b5998;
}
Within #DivHeader
, there are two child elements - one floated and one absolutely positioned, which do not affect the height of #DivHeader
.
If you were to set display: block
, the red background would cover the header from the top left corner of the page, rendering the header invisible.
This behavior occurs because setting position: relative
for #DivMain
creates a new stacking context that overlaps previously rendered elements.
By changing position: static
for
#DivMain</code, you would see the header content from the floated element.</p>
<p>With <code>display: inline-block
for
#DivHeader
, the element now acknowledges white space in the HTML document creating an anonymous inline box. This allows the clearance resulting from the float to contribute to the inline-block, displaying the background color accordingly.
To resolve this issue, simply add overflow: auto
and display: block
to DivHeader
.
Additionally, if you had not floated #DivLogo
, the larger font sizes in the logo elements would prevent the recognition of white space by the inline-block.
There are multiple factors at play here!