css - Prepros/XAMPP 在最后一个 div/页脚下添加不需要的空间

标签 css flexbox space prepros

尽管将所有边距和填充设置为 0,但我突然发现使用 Prepros(也尝试过 XAMPP)处理我的 html 和 css 时,会在我的下方添加额外(不需要的)空间最后一项即。页脚。直接从 Notepad++ 运行相同的 html 和 css 时,不会这样做(谢天谢地)。有人可以解释为什么会这样,因为我最终将从本地主机运行。 这是 HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf=8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <header>header</header>
    <div class="wrapper">wrapper1</div>
    <div class="wrapper">wrapper2</div>
    <footer>footer</footer>
  </body>
</html>

这是 CSS:

html {
  margin: 0;
  padding: 0;
  border: 3px solid green;
}

body {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 3px solid lightblue;
  height: 100vh;
}


header {
  flex: 1;
  height: 50%;
  background-color: red;
  border: 3px solid black;
}

.wrapper {
  flex: 1;
  height: 20%;
  background-color: blue;
  border: 3px solid black;
}

footer {
  height: 5%;
  position: absolute:
  bottom: 0;
  background-color: orange;
  margin: 0;
  padding: 0;
}

以下是运行相同代码的图像,第一个来自 file:///,另一个来自 localhost:

enter image description here

enter image description here

希望对此事作出任何澄清。注意:以上是我尝试过的每个浏览器(Chrome、Firefox 和 Opera)的差异。

最佳答案

我认为这是因为您提到了页脚的 position: absolute;。 你不应该,因为 flex 属性不再适用于 block 。 尝试对每个子项使用 flex,例如:

header, .wrapper{
  flex: 3;
}

footer{
  flex: 1;
}

它对我有用。

关于css - Prepros/XAMPP 在最后一个 div/页脚下添加不需要的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34199214/

相关文章:

css - 两个元素向右浮动后,一个元素向左浮动?

带有页脚的 jQuery DataTable 不响应

html - Flex CSS - 列表项的左边距不仅仅是最后一个 child

jquery - 在使用百分比时阻止 CSS 调整大小

c - 在 C 中注册回调函数

Java Space Invaders Game Rapid Fire 作弊触发游戏获胜过早

html - 在哪里编辑 bootstrap @grid-float-breakpoint

javascript - 溢出 : hidden of absolute positioned elements

html - 空的响应式正方形,其边长等于 flex 盒内 sibling 的高度

css - 在打印预览中显示 : -ms-flexbox ! 重要 > 使 Internet Explorer 10 崩溃