2017-08-16 19 views
-1

我試圖把一個圖像作爲一個標識鏈接,但底部總是有一個4px的空間。我知道我可以設置高度爲50px來解決問題,但我想要的高度取決於。所以,我的問題是,4px空間來自哪裏?我該如何解決它?爲什麼<img>標籤在<a>標籤的底部會有4 px的空間?

下面是代碼:

<!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> 

下面是結果(我不想在底部4PX空間): enter image description here

由於昆汀這是一個重複的問題,我感到很抱歉那。答案就在這裏「White space at bottom of anchor tag

回答

1

試試這個: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>

+0

謝謝你的回答,'display:flex;'有效,但我想知道爲什麼。但是,Quentin告訴我我的問題是重複的,我已經在「https://stackoverflow.com/questions/3197601/white-space-at-bottom-of-anchor-tag」上找到了答案。但還是要感謝你的回答。 –

相關問題