Please tell that in following html & css Snippet: –
Html:
<p>Paragraph Text</p>
<p>
<a class="cta" href="#">Visit Blog</a>
</p>
<p>Paragraph Text</p>
Css:
a.cta {
font-size:18px;
margin-top: 50px;
margin-bottom: 50px;
margin-left: 40px;
}
1) Why the top & bottom margins are Not apply To the anchor’s “cta” Class?.
and
2) Why the left margin is apply without any problem?.
You need to add
display: inline-block;to your CSSDemo
CSS
Explanation: Because
<a>is aninlineelement, inline elements doesn’t take top, bottom margins, you need to make it block level element, by declaringinline-blockorblockList of inline and block level elements