Html - Logo 和导航栏之间的空间

标签 html css

我似乎无法弄清楚为什么会这样:

image

我找不到错误,我尝试了很多解决方案,但都没有解决问题。请帮忙

body {
  margin: 0;
  padding: 0;
}
.logo {
  margin: 0;
  padding: 0;
}
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #000;
}
li {
  float: left;
}
li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li a:hover {
  background-color: #111;
}
.active {
  background-color: #222;
}
<a href="index.html" class="logo">
  <img src="img/logo.png" width=400em height=150em></img>
</a>
<div>
  <ul>
    <li><a class="active" href="index.html">Home</a></li>
    <li><a href="about.html">About</a></li>
  </ul>
</div>

最佳答案

在图像上添加了 display: block; ...

body {
  margin: 0;
  padding: 0;
}
.logo {
  margin: 0;
  padding: 0;
}
.logo img {
  display: block;
}
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #000;
}
li {
  float: left;
}
li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li a:hover {
  background-color: #111;
}
.active {
  background-color: #222;
}
<!DOCTYPE HTML>
<html>

<head>
  <title></title>
  <meta charset="utf-8" />
  <link rel="stylesheet" href="css.css" />
  <link href='https://fonts.googleapis.com/css?family=Roboto+Condensed:400,400italic' rel='stylesheet' type='text/css'>
</head>

<body>
  <a href="index.html" class="logo">
    <img src="img/logo.png" width="400em" height="150em">
  </a>
  <div>
    <ul>
      <li><a class="active" href="index.html">Home</a>
      </li>
      <li><a href="about.html">About</a>
      </li>
    </ul>
  </div>
</body>

</html>

关于Html - Logo 和导航栏之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37645950/

相关文章:

html - 将顶部和底部部分添加到 IFRAME

html - div 的背景图像在服务器上呈现不同,但在本地主机上呈现不同

javascript - 保存动态页面以供导航

html - 如何将段落中心的第一行与图像对齐。而其他行和第一行的缩进是一样的吗?

javascript - 如何删除某个div之后的div中的所有元素

html - 文本未在我的 li 中居中

html - 将 col-md-6 div 并排放置

javascript - 相对两侧的提交和取消按钮

css - 是否可以链接 :not() then :last-child?

css - 为什么 BEM 经常使用两个下划线而不是一个下划线作为修饰符?