html - 谁能告诉我为什么我的 div 之间有 <body> 空间?

标签 html css alignment

所以我是编码之类的新手,我想知道为什么 this fiddle 中的 div 之间有一个 body 空间。 ?

HTML:

<!DOCTYPE html>

<html lang="en">
<head>
  <title>title</title>
  <link href="main.css" rel="stylesheet" type="text/css">
  <meta charset="UTF-8">
</head>
  <!-- body -->
<body>
  <div class="top-navbar navbar" id="color-1">
    <a href="about.html">About</a>
    <a href="art.html">Art</a>
    <a href="home.html">Home</a>
  </div>

  <div class="image">
    <img src="sgrumble.png" alt="sg-rumble" class="front-image">
  </div>

  <div class="top-bar-2 navbar" id="color-1">
    <a href="#project">Project</a>
    <a href="#divname">Champions</a>
    <a href="#divname2">divname2</a>
    <a href="#divname3">divname3</a>
  </div>

  <div class="about-text" id="color-1">
    <h4>title</h4>
    <p>short info text about text text text text text text text text text</p>
  </div>

  <div class="collection art" id="project color-2">
    <h3>text</h3>
    <p>text.</p>

    <div class="project-blue">
      <img src="/asset/images/project-ashe256x256.png" class="project-ashe">
    </div>

CSS:

body {
    margin: 0;
    padding: 0;
  background-color: green;
}
#color-1 {
    background-color: #d3d3d3;
}
#color-2 {
    background-color: #fff;
}
.top-navbar {
    width: 100%;
    height: 50px;
}
.top-navbar a {
    padding: 14px 16px;
    text-align: center;
    float: right;
    display: block;
    color: black;
    text-decoration: none;
}
.top-navbar a:hover {
    background-color: #8a8a8a;
}
.image {
    width: 100%;
    height: 491px;
    background-color: red;
}
.top-bar-2 {
    width: 100%;
    height: 50px;
    text-align: center;
}
.top-bar-2 a {
    padding: 14px 16px;
    text-align: center;
    display: inline-block;
    color: black;
    text-decoration: none;
}
.top-bar-2 a:hover {
    background-color: #8a8a8a;
}
.collection {
    height: 300px;
    width: 100%;
    text-align: center;
    background-color: blue

主体部分的绿色部分显示在第二个导航栏和两个文本 div 之间。任何人都知道出了什么问题,因为我找不到它。

最佳答案

h4 和 p 元素设置了边距。您可以使用“检查”选项在浏览器中右键单击该元素看到这一点。

关于html - 谁能告诉我为什么我的 div 之间有 <body> 空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45898014/

相关文章:

java - span html 标签的模式编译器

javascript - 如何使用 javascript 创建表格

jquery - 用 JQuery 替换 HTML 中的图像、视频大小

javascript - 字符串 toFixed 用 javascript 吗?

javascript - 无法在 Canvas 中引用窗口宽度/高度

html - 无法水平对齐 h2 和 Button

android - 将 Activity 对齐为左上角的对话框

html - 我怎样才能在右上角并排显示这些按钮?

jquery - 如何使用jQuery淡入/淡出li a :hover css background-color?

css - 在多行上下文中具有响应式等宽的元素组,最后一行问题