-1

I have this code that should create a sticky navigation bar on the top of the site:

#navigation-bar {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: rgb(225, 151, 77, 0.95);
    overflow: hidden;
    position: sticky;
    top: 0;
}

#navigation-bar li {
    float: left;
}

#navigation-bar li a {
    color: white;
    padding: 5px;
    text-decoration: none;
    display: block;
    text-align: center;
    font-family: sans-serif;
}

#navigation-bar li a:hover {
    background-color: red;
    color: rgb(225, 151, 77);
}

header {
    position: sticky;
    top: 0;
}

#navigation-home-logo {
    height: 50px;
    padding: 0;
    margin: 0;
}


<header>
    <nav>
        <ul id="navigation-bar">
            <li><a href=""><img  id="navigation-home-logo" src=""></a></li>
            <li><a href="">INSTAGRAM</a></li>
            <li><a href="">TIKTOK</a></li>
            <li><a href="">TWITTER</a></li>
            <li><a href="">YOUTUBE</a></li>
        </ul>
    </nav>
</header>

I don't understand why the other links are not lining vertically with the image, I tried setting the image padding and margin to 0 but obv it didn't work and I have no idea of what the problem is enter image description here

newbie
  • 15
  • 2
  • 7

2 Answers2

0

This happens because that's how display: block works, you can use Flex in order to do so. Like:

#navigation-bar {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: rgb(225, 151, 77, 0.95);
    overflow: hidden;
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
}

#navigation-bar li {
    float: left;
}

#navigation-bar li a {
    color: white;
    padding: 5px;
    text-decoration: none;
    display: block;
    text-align: center;
    font-family: sans-serif;
}

#navigation-bar li a:hover {
    background-color: red;
    color: rgb(225, 151, 77);
}

header {
    position: sticky;
    top: 0;
}

#navigation-home-logo {
    height: 50px;
    padding: 0;
    margin: 0;
}
<header>
    <nav>
        <ul id="navigation-bar">
            <li><a href=""><img  id="navigation-home-logo" src="https://picsum.photos/200"></a></li>
            <li><a href="">INSTAGRAM</a></li>
            <li><a href="">TIKTOK</a></li>
            <li><a href="">TWITTER</a></li>
            <li><a href="">YOUTUBE</a></li>
        </ul>
    </nav>
</header>
Gonzalo F S
  • 412
  • 3
  • 8
  • 1
    Yeah i figured out it was changing only the a tag, thx for the answer btww – newbie May 21 '21 at 06:21