Home > front end >  I don't know where the extra space is from
I don't know where the extra space is from

Time:02-17

Checkout this codepen. codepen project resize the window and you will see extra space below the image. I don't know how to get rid of it. The image is in a table. And if you don't mind, drop an advice on how to better do what I did. I am doing the freeCodeCamp project. "It looks like your post is mostly code; please add some more details." Stack overflow Here is the 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>

CodePudding user response:

Tables are hardly responsive, nor are they as easy to manipulate as would using divs would be. Another solution would be to use div's instead.

I went ahead and replaced the table with divs. I removed the default margin on p.

Then I added display: flex; on #logo-table. I also removed some of the margins you had set on some of the nav components to reduce spacing. See the changes I made under /* 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>

CodePudding user response:

I’m not clear where in your example you're seeing this, but I suspect you're referring to the space below the baseline—images display inline-block by default, so they sit on the baseline (i.e. bottom of your standard lowercase letters). The easiest way to get rid of it is to set it to display: block.

  • Related