【问题标题】:Why does the div named boxes is above the footer? And why may the footer have all that extra white space below it?为什么div命名框在页脚上方?为什么页脚下面会有那么多额外的空白?
【发布时间】:2020-09-09 19:12:16
【问题描述】:

我的意思是关于带有类 box 的 div,它应该是 box1 和 box2 的容器,但它在下面,就在页脚上方。 此外,如果您认为我可以更好/更有效地确定事情,告诉我也会很有帮助(例如,不需要某些 div,另一种方法会更好地定位元素,代码可以更简洁等。 ) 非常感谢。

HTML 代码(为简单起见,此处未复制标题和标题):

<body>
  
    <main>
        <section class="introduction">
            <div class="container-intro">
        <h1 class="header1">The Future Is Here</h1>
            </div>
                <div class="boxes"> 
                    <div class="box1"><a href="#">Sign Up</a></div>
                    <div class="box2"><a href="#">Sign In</a></div>
                </div>
        </section>
    </main>
    
    <footer>
       <ul class="smedia-icons">
        <li><i class="fab fa-twitter-square"></i></li>
        <li><i class="fab fa-facebook"></i></li>
        <li><i class="fab fa-whatsapp-square"></i></li>
        <li><i class="fab fa-instagram-square"></i></li>
       </ul>

    </footer>
    
</body>
</html>

CSS:

   *{
    font-family: 'Orbitron', sans-serif;
    margin: 0px;
    color: white;
}

main{
background: linear-gradient(#ff416c, #ff4b2b);
margin-top: 0px;
}
.header1{
text-align: center;
padding: 270px;
color: white;
font-size: 90px;
}
footer{
  background-color: black;
  color: white;
  padding: 50px;
  position: relative;
  height: 100%;
}
.smedia-icons li{
  display: inline-block;
  list-style: none;
  font-size: 40px;
  margin: 10px;
  position: relative; top: 950px;
  
}
.boxes{
 text-align: center;
 display: flex;
 justify-content: center;
 font-size: medium;
 font-weight: bolder;

}

.box1{
  height: 30px ;
  width: 150px ;
  padding: 10px ;
  border: ;
  border-radius: 40px;
  background-color: black;
  margin: 0 auto;
  position: relative; top: -200px; left: 200px;

}
.box2{
  height: 30px ;
  width: 150px ;
  padding: 10px ;
  border: ;
  border-radius: 40px;
  background-color: black;
  margin: 0 auto;
  position: relative; top: -200px; left: -200px;

}
.box1:hover, .box2:hover{
  background-color: chartreuse;
}

【问题讨论】:

  • 我在footer 下看不到空白。带有class boxesdiv 位于footer 上方,因为它在HTML 标记中位于footer 上方?见codepen.io/larrytherabbit/pen/NWNYNoj
  • 我的意思是 div 框应该是 box1 和 box2 的容器,但实际上是在下面。同样在页脚中,我看不到社交媒体图标。关于空白,在您的链接中它不存在,但是当我在 Chrome 或 Safari 中打开文件时,它就在那里。
  • 啊,好吧,因为 .boxes 没有定义任何高度或宽度,所以看起来像这样,但 box1 和 box2 完全在 .boxes 内。
  • 那么 .boxes 在那里还可以,还是我应该改变它?另外,关于您的链接的问题:为什么页面有不同的字体并且没有出现社交媒体图标?如果您知道页脚下方的空白(出现在 chrome 和 safari 中)有什么问题,我们将不胜感激
  • 看我的回答,盒子没问题。您的图标未在
  • 标签内显示 b/c,不知道为什么。所以我使用了 flexbox 布局,它看起来不错。

标签: html css


【解决方案1】:

Codepen:https://codepen.io/larrytherabbit/pen/NWNYNoj

对代码的唯一修改是删除 &lt;li&gt;&lt;/li&gt; 标签并在 .smediaicons div 内使用 flex 显示,社交媒体图标的左右边距为 15 像素。我还使用了 45px 的字体大小。

HTML

<body>
  <main>
    <section class="introduction">
      <div class="container-intro">
        <h1 class="header1">The Future Is Here</h1>
      </div>
      <div class="boxes">
        <div class="box1">
          <a href="#">Sign Up</a>
        </div>
        <div class="box2">
          <a href="#">Sign In</a>
        </div>
      </div>
    </section>
  </main>
  <footer>
    <div class="smedia-icons">
        <i class="fab fa-twitter-square"></i>
        <i class="fab fa-facebook"></i>
        <i class="fab fa-whatsapp-square"></i>
        <i class="fab fa-instagram-square"></i>
      </div>
  </footer>
</body>

CSS

  *{
    font-family: 'Orbitron', sans-serif;
    margin: 0px;
    color: white;
}

main{
background: linear-gradient(#ff416c, #ff4b2b);
margin-top: 0px;
}

.smedia-icons {
  display:flex;justify-content:center;
}
.header1{
text-align: center;
padding: 270px;
color: white;
font-size: 90px;
}
footer{
  background-color: black;
  color: white;
  padding: 50px;
  position: relative;
  height: 100%;
}
.smedia-icons i{
font-size:45px;
  margin:0 15px;
 
}
.boxes{
 text-align: center;
 display: flex;
 justify-content: center;
 font-size: medium;
 font-weight: bolder;

}

.box1{
  height: 30px ;
  width: 150px ;
  padding: 10px ;
  border: ;
  border-radius: 40px;
  background-color: black;
  margin: 0 auto;
  position: relative; top: -200px; left: 200px;

}
.box2{
  height: 30px ;
  width: 150px ;
  padding: 10px ;
  border: ;
  border-radius: 40px;
  background-color: black;
  margin: 0 auto;
  position: relative; top: -200px; left: -200px;

}
.box1:hover, .box2:hover{
  background-color: chartreuse;
}

【讨论】:

  • 非常感谢。两件事:社交媒体图标旁边有项目符号(当我在 chrome 或 safari 中打开它时),我试图用 list-style: none 删除它;但仍然无法删除,第二件事是:您认为您所做的哪些更改可以解决页脚下方额外空间的问题?另外,当我使用 chrome 检查元素并将鼠标悬停在 s 媒体图标上时,在代码中它们仍然在
      中显示为
    • ,为什么会这样?
  • 这是不可能的,因为我完全删除了 ul 和 li 标签。您必须加载旧的缓存版本或类似的东西。在codepen上,没有要点?让我知道。对于页脚,当您使用“footer”标签时(您使用的是 id="footer"),默认情况下它位于最底部。
  • 谢谢!关于页脚下方空白的那件事很奇怪,我上传的问题中的代码没有 id 页脚,它有页脚标签,所以现在不要有什么问题。此外,当我在 chrome 中打开文件时,页脚很好,但是当我检查页面时,页脚下方的空白仍然存在几个屏幕尺寸,主要从 1300 x 1165 向上。
  • 抱歉,我无法在任何窗口宽度上重现该空白区域。
猜你喜欢
相关资源
最近更新 更多
热门标签