html - 从代码中删除段落后,页脚会更改其 UI

标签 html css

我在页脚的 HTML 中有以下代码。

    <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" type="text/css" href="style_testfooter.css">
</head>
<body>
<div class="footer">
  <p>hello</p>
</div>


<div class="footerdark">
    <p> hello</p>
</div>

</body>
</html> 

同样的CSS代码如下:

.footer {
   position: relative;
   left: 0;
   bottom: 110px;
   width: 100%;
   background-color: #303740;
   color: white;
   text-align: center;
   padding: 160px 0px;
}

.footerdark {
   position: relative;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: #272d35;
   color: white;
   text-align: center;
   padding: 30px 0px;
}

当我尝试从 html 代码中删除 para 标签时,页脚的 UI 发生了变化。原因/错误是什么?

Before removal of p tags

After removal of p tags

最佳答案

您的 .footer 类设置了底值。目前,在 p 标签就位的情况下,它正在改变较低的页脚高度以足以覆盖该空白区域。我建议删除 bottom: 110px

注意 p 标签是 block 级元素,因此它们横跨其父元素的整个宽度并具有设置的高度,这会影响其父元素的高度。

关于html - 从代码中删除段落后,页脚会更改其 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50309530/

相关文章:

javascript - 选择选项更改时发出警报

javascript - JavaScript 中的生命游戏 - 使用 Table

html - "submit"按钮的样式

CSS 沿边界对齐元素,而不是基线或顶部

html - CSS: make overflow-x: hidden 真的隐藏了吗?

html - 如何在页面顶部创建一个倾斜的 div 标题

html - 如何创建圆点边框?

html - 如何在本地环境中通过 CSS 显示图像?

html - 进一步推出子子菜单

css - 使用 css 将 <br> 替换为字符/字符串?