-1

I am trying to put an image inside of as a logo link, but there is always a 4px space on the bottom. I know I can set height 50px for to solve the problem, but I want the height of is depend on the . So, my question are, where is 4px space come from? And How can I solve it?

Here is the code:

<!DOCTYPE HTML>
<html lang="en">
  <head>
    <style>
      body{
        margin: 0;
        padding: 0;
      }

      nav{
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        background: rgba(0,0,0,0.5);
        z-index: 10;
      }

      a{
        text-decoration: none;
        color: black;
      }
    </style>
  </head>

  <body>
    <nav>
      <a href="#"><img src="Logo.png" alt="Logo" width="50" height="50"></a>
    </nav>
  </body>
</html>

Here is the result(I do not want 4px space on the bottom): enter image description here

Thanks Quentin this is a duplicate question, I am sorry about that. The answer is here "White space at bottom of anchor tag"

Yode Zage
  • 159
  • 1
  • 3
  • 11

1 Answers1

1

try this: display:flex

<!DOCTYPE HTML>
<html lang="en">
  <head>
    <style>
      body{
        margin: 0;
        padding: 0;
      }

      nav{
        position: fixed;
        width:100%;
        background: rgba(0,0,0,0.5);
        z-index: 10;
      }
      a{
        text-decoration: none;
        color: black;
        display:flex;
      }
    </style>
  </head>

  <body>
    <nav>
      <a href="#"><img src="Logo.png" alt="Logo" width="50" height="50"></a>
    </nav>
  </body>
</html>
North-Wind
  • 156
  • 1
  • 12
  • Thank you for the answer, `display: flex;` works, but I would like to know why as well. However, Quentin told me my question is duplicate and I already find the answer on "https://stackoverflow.com/questions/3197601/white-space-at-bottom-of-anchor-tag". But still want to thank you for your answer. – Yode Zage Aug 16 '17 at 15:24