Margins in HTML5 - Why Margin-Top is Ignored for Inline Elements
In HTML5, some elements like span are classified as inline elements, while others like div and p are block-level elements. These classifications impact how margins are applied to these elements.
Understanding Inline Elements
Inline elements are designed to flow naturally within lines of text. They occupy the minimum possible vertical space necessary to display their content. As a result, vertical margins are not applicable to them. When you apply margin-top to an inline element like span, it is simply ignored.
Solution: Inline-Block or Block Display
To give inline elements like span a margin at the top, you have two options:
Example
Consider the following HTML and CSS code:
The above is the detailed content of Why is Margin-Top Ignored on Inline HTML Elements?. For more information, please follow other related articles on the PHP Chinese website!