I am trying to remove unwanted space in my header

2019-08-20 05:04发布

I am trying to remove this little unwanted space in the navigation bar. I have tried removing padding, margin, and border, none of which have resolved the issue. Here is my css:

.nav {
  list-style: none;
  font-family: 'Oleo Script', cursive;
  display: inline;
  margin: 0;
  padding-top: 100px;
  padding-bottom: 0px;
  float: right;
}

.header {
  background-color: rgba(0, 0, 0, .7);
  position: fixed;
  top: 0;
  padding-bottom: 0;
  margin: 0;
  width: 100%;
}
<div class=header>
  <a href="index.html">
    <img src="https://lh4.googleusercontent.com/-IqHfCyPGn00/AAAAAAAAAAI/AAAAAAAAAA8/WsxciIskxSo/photo.jpg?sz=328" alt="Logo.png" style="height:150px; width:150px; border-bottom: 0px;">
  </a>
</div>

Here is the space I am talking about:

Unwanted Space

Thanks everyone!

标签: html css web
5条回答
仙女界的扛把子
2楼-- · 2019-08-20 05:05

Your inline image has some extra margin. Give it to display: block and border: 0. It will solve your issue.

.header a img{
  border:0;
  display:block;
}
查看更多
戒情不戒烟
3楼-- · 2019-08-20 05:08

Try this and add this css:

.header a {
  display: block;
  width: 150px;
  height: 150px;
}
.header img{
  height: auto;
  width: auto;
  max-width: 100%;
  max-height: 100%;
}

.nav {
  list-style: none;
  font-family: 'Oleo Script', cursive;
  display: inline;
  margin: 0;
  padding-top: 100px;
  padding-bottom: 0px;
  float: right;
}

.header {
  background-color: rgba(0, 0, 0, .7);
  position: fixed;
  top: 0;
  padding-bottom: 0;
  margin: 0;
  width: 100%;
}
.header a {
  display: block;
  width: 150px;
  height: 150px;
}
.header img{
  height: auto;
  width: auto;
  max-width: 100%;
  max-height: 100%;
}
<div class=header>
  <a href="index.html">
    <img src="https://lh4.googleusercontent.com/-IqHfCyPGn00/AAAAAAAAAAI/AAAAAAAAAA8/WsxciIskxSo/photo.jpg?sz=328" alt="Logo.png" style="height:150px; width:150px; border-bottom: 0px;">
  </a>
</div>

查看更多
不美不萌又怎样
4楼-- · 2019-08-20 05:09

Just add the following css.

.header a img {
display:block;
}
查看更多
够拽才男人
5楼-- · 2019-08-20 05:16

The "img" element is an "inline" element, it's just a any other letter, like "n", "h" or .... "p". They have "descending" parts, and the positioning for inline elements is "baseline" (where the bottom of the "n" rests)... so what you see under the image is not a margin or padding, but the area of the line for descending part of the characters p, g ,j... You can change the display to block, as sugessted by other answers, or simply set vertical-align:bottom.

The default vertical-align value for inline elements is baseline, which is the reason behind display:block being working... it's not in line content!

line-height: 0 will also works for you if there is nothing else in the line.

查看更多
时光不老,我们不散
6楼-- · 2019-08-20 05:32

I think it might be the default value for margin-bottom attribute. You can follow the code shared by @AnkitaPatel. But, you can also try changing the margin-bottom attribute to "margin-bottom:0px" in your CSS

查看更多
登录 后发表回答