Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

html - There are weird spaces between div and div

I'm making a menu of the pizzas. and I found a little space between div and div. I think there is a problem with position:relative. When I change relative to absolute, it's okay. but if I use relative. there are spaces. I really need your help. I wrote a comment at where I found the problem. Please check.

body {
  background-color: rgb(209, 209, 209);
  text-align: center;
  letter-spacing: -1px;
}

.title-container {}

.title-container h1 {
  color: #d35400;
  font-size: 3em;
  letter-spacing: -3px;
}

.title-container h4 {
  color: rgba(0, 0, 0, .8)
}

.item-box1 {
  margin: .7em;
  width: 25em;
  height: 13em;
  background-color: white;
  display: inline-block;
}

.item-box1 h1 {
  position: relative;
  bottom: 80%;
  left: 10%;
}

.item-box1 h4 {
  bottom: 90%;
  position: relative;
  left: 49%;
  text-align: left;
  font-weight: 400;
  font-style: italic;
}

.image {
  width: 10rem;
  height: 10rem;
  position: relative;
  top: 11%;
  left: -25%;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div id="title-container" class="title-container">
    <h1>Menu</h1>
    <h4>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sequi id amet sit pariatur nemo cupiditate earum <br>numquam hic qui ratione molestias molestiae tempore placeat, libero neque odio <br> vero officiis ad?</h4>
  </div>

  <div id="item-box-container" class="item-box-container">
    <div>
      <!--This div-->
      <div id="item-box" class="item-box1">
        <img class="image" src="https://photos.bigoven.com/recipe/hero/baked-potato-pizza-8.jpg?h=500&w=500" alt="">
        <h1>Potato</h1>
        <h4>Includes potato, tomato,<br> cheese.</h4>
      </div>
      <div id="item-box" class="item-box1">
        <img class="image" src="https://photos.bigoven.com/recipe/hero/baked-potato-pizza-8.jpg?h=500&w=500" alt="">
        <h1>Potato</h1>
        <h4>Includes potato, tomato,<br> cheese.</h4>
      </div>
    </div>
    <div>
      <!--And this div-->
      <div id="item-box" class="item-box1">

      </div>
      <div id="item-box" class="item-box1">

      </div>
    </div>
  </div>
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This space appears because the "item-box1" class has CSS "height: 13em". Removing this will solve this problem and you can add some padding for an inner gap of the div.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...