Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image goes down inside navbar

In the code below, I have a navbar where I specify the height to be 40px, in #nav {... height:40px;} On the left of this navbar, I put a logo image. To make everything fit, I have resized the image to have height 40px also. Yet, as can be seen in the demo, the image goes down and is partially hidden.

What am I doing wrong ?

body {
  background: #666;
  color: white;
  font-family: Helvetica;
}

a {
  color: white;
  text-decoration: none;
}

ul {
  padding: 0;
}

#container {
  background: #333;
  width: 400px;
  margin: 30px auto;
  overflow: hidden;
}

#nav {
  background: #666;
  height: 40px;
}

#nav ul {
  padding-top: 13px;
  padding-left: 10px;
}

.lileft .li {
  list-style: none;
  float: left;
}

.lileft img {
  display: block;
}

#nav li {
  list-style: none;
  float: right;
  padding-right: 20px;
}

      
<div id="container">
      <div id="nav">
        <ul>
          <lileft><a href="https://imgbb.com/"><img src="https://i.ibb.co/WVxqWc7/crown.png" alt="crown" border="0"></a></li>
          <li><a href="pears.html">Pears</a></li>
          <li><a href="grapes.html">Grapes</a></li>
          <li><a href="apples.html">Apples</a></li>
          <li><a href="oranges.html">Oranges</a></li>
        </ul>
      </div>
    </div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s cause you have padding-top on your ul which is affecting the first-child (image).

Set the padding on the li instead and exclude the :first-child using the :not() pseudo-class.

body {
  background: #666;
  color: white;
  font-family: Helvetica;
}

a {
  color: white;
  text-decoration: none;
}

ul {
  padding: 0;
}

#container {
  background: #333;
  width: 400px;
  margin: 30px auto;
  overflow: hidden;
}

#nav {
  background: #666;
  height: 40px;
}

#nav ul {
  padding-left: 10px;
}

#nav ul > li:not(:first-child) {
  padding-top: 13px;
}

#nav li {
  list-style: none;
  float: right;
  padding-right: 20px;
}
<div id="container">
  <div id="nav">
    <ul>
      <lileft>
        <a href="https://imgbb.com/"><img src="https://i.ibb.co/WVxqWc7/crown.png" alt="crown" border="0"></a>
      </lileft>
      <li><a href="pears.html">Pears</a></li>
      <li><a href="grapes.html">Grapes</a></li>
      <li><a href="apples.html">Apples</a></li>
      <li><a href="oranges.html">Oranges</a></li>
    </ul>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading