0

Trying to create a margin to move header elements away from the top of the page. Margin-top is not working for some reason.

The page can be found at this link: https://jevoncochran.github.io/Documents/My%20Site/html/bd_index.html

HTML:

<container class="universal-header">
    <div class="header-top">
        <div class="social-media">
            <i class="fab fa-youtube-square" style="font-size: 2.5rem"></i>
            <i class="fab fa-instagram" style="font-size: 2.5rem"></i>
            <i class="fab fa-facebook" style="font-size: 2.5rem"></i>
            <i class="fab fa-pinterest" style="font-size: 2.5rem"></i>
            <i class="fab fa-twitter-square" style="font-size: 2.5rem"></i>
        </div>
        <nav>
            <a href="#">Home</a>
            <a href="#">Stories</a>
            <a href="#">Travel Resources</a>
            <a href="#">About</a>
            <a href="#">Contact</a>
            <a href="#">Shop</a>
        </nav>
    </div>

    <h1>Black Diasporer</h1>
</container>

CSS:

.universal-header {
  margin-top: 5%;
}
sebastienbarbier
  • 6,542
  • 3
  • 29
  • 55
Jevon Cochran
  • 1,565
  • 2
  • 12
  • 23

1 Answers1

1

Replace <container> by a <div> and your margin can apply. The reason is as <container> is not a valid HTML markup, the browser do not know how to display it and ignores it.

<div class="universal-header">
    <div class="header-top">
        <div class="social-media">
            <i class="fab fa-youtube-square" style="font-size: 2.5rem"></i>
            <i class="fab fa-instagram" style="font-size: 2.5rem"></i>
            <i class="fab fa-facebook" style="font-size: 2.5rem"></i>
            <i class="fab fa-pinterest" style="font-size: 2.5rem"></i>
            <i class="fab fa-twitter-square" style="font-size: 2.5rem"></i>
        </div>
        <nav>
            <a href="#">Home</a>
            <a href="#">Stories</a>
            <a href="#">Travel Resources</a>
            <a href="#">About</a>
            <a href="#">Contact</a>
            <a href="#">Shop</a>
        </nav>
    </div>

    <h1>Black Diasporer</h1>
</div>

Custom HTML elements in browser are handled as web components, and I guess this it not what you were trying to do.

sebastienbarbier
  • 6,542
  • 3
  • 29
  • 55
  • 1
    it's a vaild HTML but any custom element is by default display:initial which means inline and inline elements doesn't obey to margin-top/bottom – Temani Afif Oct 30 '19 at 08:07