Can someone tell me what I coded wrong? Everything is working, the only thing is that there is no margin at the top.
HTML:
<div id="contact_us"> <!-- BEGIN CONTACT US -->
<span class="first_title">Contact</span>
<span class="second_title">Us</span>
<p class="content">For any questions whatsoever please contact us through the following e-mail address:</p></br></br>
<p class="e-mail">info@e-mail.com</p></br></br></br></br>
<p class="read_more"><a href="underconstruction.html">Read More</a></p>
</div> <!-- END CONTACT US -->
CSS:
span.first_title {
margin-top: 20px;
margin-left: 12px;
font-weight: bold;
font-size: 24px;
color: #221461;
}
span.second_title {
margin-top: 20px;
font-weight: bold;
font-size: 24px;
color: #b8b2d4;
}
Looks like you missed some options, try to add:
span
is an inline element that doesn't support vertical margins. Put the margin on the outerdiv
instead.Unlike
div
,p
1 which are Block Level elements which can take upmargin
on all sides,span
2 cannot as it's an Inline element which takes up margins horizontally only.From the specification:
Demo 1 (Vertical
margin
not applied asspan
is aninline
element)Solution? Make your
span
element,display: inline-block;
ordisplay: block;
.Demo 2
Would suggest you to use
display: inline-block;
as it will beinline
as well asblock
. Making itblock
only will result in your element to render on another line, asblock
level elements take100%
of horizontal space on the page, unless they are madeinline-block
or they arefloated
toleft
orright
.1. Block Level Elements - MDN Source
2. Inline Elements - MDN Resource
Always remember one thing we can not apply margin vertically to inline elements ,if you want to apply then change its display type to block or inline block.for example span{display:inline-block;}
span
element isdisplay:inline;
by default you need to make itinline-block
orblock
Change your CSS to be like this