Prepros/XAMPP adding unwanted space under last div/footer

六月ゝ 毕业季﹏ 提交于 2019-12-14 04:04:31

问题


In spite of setting all margins and padding to 0, I'm suddenly finding that processing my html & css using Prepros(also tried with XAMPP), is adding extra (unwanted) space under my last item ie. footer. While running the same html & css directly from Notepad++, does not do this (thankfully). Can someone please explain why this is happening since I will eventually be running from a local host. Here is the 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>

Here is the 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;
}

Here are images of the same code running, first from file:/// and the other from localhost:

Would appreciate any clarification on this matter. NOTE: Above is the discrepancy in every browser i tried it on (Chrome, Firefox and Opera).


回答1:


I think it's because you mentionned a position: absolute; for the footer. You shouldn't, because flex property does not apply anymore on the block. Try the use flex for each children items, like:

header, .wrapper{
  flex: 3;
}

footer{
  flex: 1;
}

It works for me.



来源:https://stackoverflow.com/questions/34199214/prepros-xampp-adding-unwanted-space-under-last-div-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!