我不知道额外的 space 来自哪里

I don't know where the extra space is from

查看此代码笔。 codepen project 调整 window 的大小,您会在图像下方看到额外的 space。我不知道如何摆脱它。图片在 table 中。如果你不介意,就如何更好地做我所做的事情提出建议。 我正在做 freeCodeCamp 项目。 “看起来您的 post 主要是代码;请添加更多详细信息。”堆栈溢出 这里是 html.

@import 'https://fonts.googleapis.com/css?family=Lato:400,700';
html {
  height: 100%;
  margin: 0;
}

body {
  height: 100%;
  top: 10px;
  padding: 0;
  margin: 0 30px 0 30px;
  background-color: rgb(30, 60, 90, 0.1);
  font-family: 'Lato', sans-serif;
}

header {
  position: sticky;
  margin: 10px auto;
  width: 100%;
  height: fit-content;
}

#navbar {
  width: 100%;
  height: 150px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  transition: all 1s;
}

@media (max-width: 750px) {
  #navbar {
    transform: scale(0.9);
    flex-direction: column;
    justify-content: space-evenly;
    text-align: center;
  }
}

#header-img {
  height: 80px;
  align-self: center;
}

#company {
  font-size: 36pt;
  font-style: bold;
  color: rgb(30, 60, 90);
}

#nav-bar {
  align-self: center;
  margin: 0;
}

table {
  align-self: center;
  width: fit-content;
  height: 150px;
}

@media (max-width: 480px) {
  #logo-table {
    transition: all 1s;
    transform: scale(0.8);
    justify-self: space-around;
    margin: auto;
  }
}

@media (max-width: 320px) {
  #logo-table {
    transition: all 1s;
    transform: scale(0.6);
    justify-self: center;
    margin: auto;
  }
}

ul {
  display: flex;
  justify-content: space-around;
  list-style: none;
}

@media (max-width: 480px) {
  #nav-bar {
    width: 100%;
  }
  ul {
    flex-direction: column;
    justify-content: space-between;
  }
}

li {
  width: max-content;
  transition: all 0.3s ease-in-out;
}

li:hover {
  transform: scale(1.5);
}

@media (max-width: 480px) {
  li {
    flex-direction: column;
    align-self: center;
    justify-self: space-around;
    padding-bottom: 15px;
  }
}

a {
  color: black;
  text-decoration: none;
  margin: 20px;
}


/* End of nav bar decorations*/

main {
  display: block;
  top: 0;
  margin: 0;
}

#top {
  margin: 20px auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}

h1 {
  text-align: center;
}

#email {
  display: flex;
  width: 200px;
  margin: auto;
  padding: 8px;
}

#submit {
  display: block;
  margin: 15px auto;
  padding: 5px;
  width: 50%;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Product landing page</title>
</head>

<body>
  <header>
    <div id="navbar">
      <table id="logo-table">
        <tr>
          <th><img src="https://festive-hypatia-ab69c7.netlify.app/dumbbell.png" alt="logo" id="header-img"></th>
          <th>
            <p id="company"><strong>Dumbbell</strong> </p>
          </th>
        </tr>
      </table>

      <nav id='nav-bar'>
        <ul>
          <li><a href=""> Features</a></li>
          <li><a href=""> How it works</a></li>
          <li><a href=""> Pricing</a></li>
        </ul>

      </nav>
    </div>

  </header>
  <main>
    <section id="top">
      <h1>Dumbbell everyone</h1>
      <form action="submit" id="form">
        <input type="email" placeholder="Enter your email address" id="email">

        <input type="submit" value="GET STARTED" id="submit">
      </form>
    </section>


    <section id="features">

    </section>
    <section id="vid">
      <iframe src="" frameborder="0" id="video"></iframe>
    </section>
    <section id="pricing">
      <div></div>
      <div></div>
      <div></div>
    </section>
  </main>
  <footer></footer>
</body>

</html>

我不清楚您在示例中的哪个位置看到了这一点,但我怀疑您指的是基线以下的 space——图像默认显示 inline-block,因此它们坐在基线上(即标准小写字母的底部)。摆脱它的最简单方法是将其设置为 display: block.

表格几乎没有响应,也不像使用 div 那样容易操作。另一种解决方案是改用 div

我继续将 table 替换为 div。我删除了 p.

上的默认边距

然后我在 #logo-table 上添加了 display: flex;。我还删除了您在某些导航组件上设置的一些边距以减少间距。查看我在 /* added CSS */

下所做的更改

@import 'https://fonts.googleapis.com/css?family=Lato:400,700';
html {
  height: 100%;
  margin: 0;
}

body {
  height: 100%;
  top: 10px;
  padding: 0;
  margin: 0 30px 0 30px;
  background-color: rgb(30, 60, 90, 0.1);
  font-family: 'Lato', sans-serif;
}

header {
  position: sticky;
  width: 100%;
  height: fit-content;
}

#navbar {
  width: 100%;
  height: 150px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  transition: all 1s;
}

@media (max-width: 750px) {
  #navbar {
    transform: scale(0.9);
    flex-direction: column;
    justify-content: space-evenly;
    text-align: center;
  }
}

#header-img {
  height: 80px;
  align-self: center;
}

#company {
  font-size: 36pt;
  font-style: bold;
  color: rgb(30, 60, 90);
}

#nav-bar {
  align-self: center;
  margin: 0;
}

table {
  align-self: center;
  width: fit-content;
  height: 150px;
}

@media (max-width: 480px) {
  #logo-table {
    transition: all 1s;
    transform: scale(0.8);
    justify-self: space-around;
    margin: auto;
  }
}

@media (max-width: 320px) {
  #logo-table {
    transition: all 1s;
    transform: scale(0.6);
    justify-self: center;
    margin: auto;
  }
}

ul {
  display: flex;
  justify-content: space-around;
  list-style: none;
}

@media (max-width: 480px) {
  #nav-bar {
    width: 100%;
  }
  ul {
    flex-direction: column;
    justify-content: space-between;
  }
}

li {
  width: max-content;
  transition: all 0.3s ease-in-out;
}

li:hover {
  transform: scale(1.5);
}

@media (max-width: 480px) {
  li {
    flex-direction: column;
    align-self: center;
    justify-self: space-around;
    padding-bottom: 15px;
  }
}

a {
  color: black;
  text-decoration: none;
  margin: 20px;
}


/* End of nav bar decorations*/

main {
  display: block;
  top: 0;
  margin: 0;
}

#top {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}

h1 {
  text-align: center;
}

#email {
  display: flex;
  width: 200px;
  margin: auto;
  padding: 8px;
}

#submit {
  display: block;
  margin: 15px auto;
  padding: 5px;
  width: 50%;
}

/* added CSS */
#logo-table {
  display: flex;
  justify-content: center;
  align-items: center;
}

p {
  margin: 0 !important;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Product landing page</title>
</head>

<body>
  <header>
    <div id="navbar">
      <div id="logo-table">
        <img src="https://festive-hypatia-ab69c7.netlify.app/dumbbell.png" alt="logo" id="header-img">
        <p id="company"><strong>Dumbbell</strong> </p>
      </div>
    <nav id='nav-bar'>
      <ul>
        <li><a href=""> Features</a></li>
        <li><a href=""> How it works</a></li>
        <li><a href=""> Pricing</a></li>
      </ul>

    </nav>
    </div>

  </header>
  <main>
    <section id="top">
      <h1>Dumbbell everyone</h1>
      <form action="submit" id="form">
        <input type="email" placeholder="Enter your email address" id="email">

        <input type="submit" value="GET STARTED" id="submit">
      </form>
    </section>


    <section id="features">

    </section>
    <section id="vid">
      <iframe src="" frameborder="0" id="video"></iframe>
    </section>
    <section id="pricing">
      <div></div>
      <div></div>
      <div></div>
    </section>
  </main>
  <footer></footer>
</body>

</html>