<html>
<body>
<div style="display: inline; background-color: #555;">
<h3>test</h3>
</div>
</body>
</html>
Here is my code. I am wondering why my background color isn’t showing. If I change css display from inline to block, then it show up. Why is it not showing up if display is inline? I am trying to understand the reason of the problem other than looking for a solution.
The div doesn’t take up space if it’s inline. if you want an inline element that shows as the children’s height, then use
display: inline-block;.As for a good discussion, I’d trust QuirksMode‘s take better than my own. The gist is that an
inlineelement doesn’t push other elements out of the way.