简体   繁体   English

HTML-页脚不在底部

[英]HTML - Footer not at the bottom

I want the footer be pushed down and appear as last element of the page. 我希望页脚被按下并显示为页面的最后一个元素。 However as the content wrapper before has a height of 100%. 但是,由于内容包装器之前的高度为100%。 The content's height exceeds the height of the browser height. 内容的高度超过了浏览器的高度。 In the end the footer appears after the browserheight and not after the content wrapper. 最后,页脚出现在浏览器高度之后,而不是内容包装器之后。 How can I change it and still have a 100% height of the wrapper, that is needed for the background design. 我如何更改它,并且仍然有100%的包装高度,这是背景设计所需的。

codepen codepen

HTML HTML

<div class="content_wrap">
content wrap
<div class="item">content</div>
</div>
<footer>footer</footer>

CSS CSS

body, html{
  height: 100%;
}

.content_wrap{
  height: 100%;
  width: 100%;

  border: 2px solid black;
}

.item{
  height: 1300px;
  width: 100%;

      background: red;
}

footer{
  height: 100px;
  width: 100%;
  background: yellow;
}

Give the body position property value of relative and position property value of absolute & bottom value of -(footer Height) for the footer 给出页脚的相对位置的身体位置属性值和-(footer Height)的绝对值和底值的位置属性值

  body { height: 100%; position: relative; } .content_wrap { height: 100%; width: 100%; border: 2px solid black; } .item { height: 1300px; width: 100%; background: red; } footer { height: 100px; width: 100%; background: yellow; position: absolute; bottom:-100px; /* minus the height of the Footer and it wont overlap any other element */ } 
 <div class="content_wrap"> content wrap <div class="item">content</div> </div> <footer>footer</footer> 

footer{ position: fixed
        bottom: 0px;
}

possible duplicate of: Bottom footer 可能的重复项:下页脚

If you use min-height: 100% instead of height: 100% on the content_wrap it will be at least 100% of the screen in height and it will grow if the content inside it is larger. 如果在content_wrap上使用min-height: 100%而不是height: 100% ,则它将至少是屏幕高度的100%,并且如果其中的内容较大,它将增长。

 body, html{ height: 100%; } .content_wrap{ min-height: 100%; width: 100%; border: 2px solid black; } .item{ height: 1300px; width: 100%; background: red; } footer{ height: 100px; width: 100%; background: yellow; } 
 <div class="content_wrap"> content wrap <div class="item">content</div> </div> <footer>footer</footer> 

    body{
      display:flex;
flex-flow:column;
height:100%;
    }

    header{
      flex:0 0 75px;
    }

    .middle-container{
      display:flex;
flex: 1 0 auto;
    }

    footer{
      flex: 0 0 25px;
    }
    <header>Header</header>
    <div class="middle-container">
      content wrap
      <div class="item">content</div>
    </div>
    <footer>footer</footer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM