Reputation: 13
In the fiddle - http://jsfiddle.net/dddaaLwL/ you can see that horizontal margins have an effect on the inline elements. and vertical margins do not have an effect. Is this right? why so?
#s1 {
margin-left: 40px;
}
#s2 {
margin-top: 40px;
}
Upvotes: 1
Views: 947
Reputation: 60563
Yes your fiddle is correct. why?
An inline element occupies only the space bounded by the tags that define the inline element.
More info HERE
<a>
,<span>
,<b>
,<em>
,<i>
,<cite>
,<mark>
, and <code>
More about Inline Elements
An inline element has, but may not be limited to, the following characteristics:
More info HERE
Upvotes: 1
Reputation: 7270
Actually, vertical margins do have an effect on inline elements, but because the element above it isn't a block, it's actually using the margin from the top of the page instead of the previous element. Let's take a quick look at the box model:
Because inline
elements don't handle bounding in the same way that block
type elements do. They can only hold data, and other inline elements, and they follow the constraints of the parent element, and only exert influence over their individual space.
However, if they were inline-block
elements, you'd see a different result:
As you can see, inline-block
elements can actually influence the behaviour of other elements, whereas inline
elements do not.
See Also:
MDN Documentation on Inline Elements
MDN Documentation on Block-level Elements
Upvotes: 1
Reputation: 202
Have a look at below jsfiddle
#s1 {
margin-left: 40px;
}
#s2 {
margin-top: 100px;
}
<span id="s1"> span 1 </span>
<br>
<br>
<span id="s2"> span 2 </span>
<p id="s2"> p 3 </p>
p and div elements are block level elements where span is an inline element and hence margin on span wont work.
Upvotes: 0