Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html css页脚不显示在页面底部_Html_Css - Fatal编程技术网

Html css页脚不显示在页面底部

Html css页脚不显示在页面底部,html,css,Html,Css,这是我的页脚代码,如何使它显示在页面底部而不是页面上方内容的正下方 /*footer */ #footer .column { float: left; width: 25%; } #footer .column div { margin: 5px; height: 200px; background: #eeeeee; } <div id="footer"> <div class="column"><div>

这是我的页脚代码,如何使它显示在页面底部而不是页面上方内容的正下方

/*footer */
#footer .column {
    float: left;
    width: 25%;
}

#footer .column div {
    margin: 5px;
    height: 200px;
    background: #eeeeee;
}

<div id="footer">
    <div class="column"><div></div></div>
    <div class="column"><div></div></div>
    <div class="column"><div></div></div>
    <div class="column"><div></div></div>
</div>
/*页脚*/
#页脚.列{
浮动:左;
宽度:25%;
}
#页脚.列div{
保证金:5px;
高度:200px;
背景:#eeeeee;
}

注意:这不需要是固定的页脚

我猜您的意思是希望页脚保持在页面底部,即使页面上没有足够的内容来填充视口的高度

如果是这种情况,您可以使用以下技巧:CSS sticky footer-,或

粘性页脚技巧通常依赖于在包装div上声明最小高度。这意味着您必须按如下方式重新格式化HTML代码:

<div id="wrap">
    <div id="content">
        /* Main body content */
    </div>
</div>

<div id="footer">
    /* Footer content here */
</div>

如果页脚高度可变,则必须使用JavaScript设置
#content
的底部填充,以及
#footer
的顶部边距。该值取决于
#footer
元素本身的计算高度。

实际上有两个主要选项:

  • 固定页脚-页脚在页面底部始终可见
  • 推式页脚-即使内容没有填满窗口,页脚也会被推到页面底部
  • 两者中比较容易的是固定页脚

    固定页脚 要使页脚固定,请在CSS中将页脚的位置设置为fixed
    位置:fixed
    ,并将页脚定位到页面底部
    底部:0px
    。下面是来自的代码片段

    压脚 推压页脚有点棘手。下面展示了当没有足够的内容时,页脚为什么不留在页面底部:

    基本上,问题的发生是因为页脚元素被“推”到其上方的元素下面,而该元素的高度没有页面的高度长。为了解决这个问题,您需要确保页脚被向下推到页面的整个高度(减去页脚的高度)

    以下是如何做到这一点:

    HTML

    <div id="container">
       <div id="header"></div>
       <div id="body"></div>
       <div id="footer"></div>
    </div>
    
    下面是一个更详细的示例,以及上面代码的源代码


    这是一个来自同一来源的示例。

    您可能需要将html元素高度设置为100%,否则页面本身将仅为内容所需的高度。我自己也遇到了这个问题。

    用很酷的效果修复了底部的页脚
    #main {padding-bottom: 150px;} /* Should have the same value of footer's height */ 
    #footer {position: relative; 
    margin-top: -150px; /* footer's height */ 
    

    检查JSFIDLE中的完整页面设计


    Bootstrap有一个页脚示例,它粘贴在页面底部:

    以下是CSS:

    html {
      position: relative;
      min-height: 100%;
    }
    body {
      /* Margin bottom by footer height */
      margin-bottom: 60px;
    }
    .footer {
      position: absolute;
      bottom: 0;
      width: 100%;
      /* Set the fixed height of the footer here */
      height: 60px;
      background-color: #f5f5f5;
    }
    
    然后在HTML中:

    <footer class="footer">
    
    </footer>
    

    我解决了这个问题,只需在HTML的主
    容器上使用
    min height

    因此,HTML:

    <body>
        <div class="top-nav">My Nav Bar</div>
        <div class="main-container">
            All my content
        </div>
        <div class="footer">
            My footer
        </div>
    </body>
    
    使用SCSS,您可以使用变量跟踪顶部导航和页脚高度,然后执行以下操作

    .main-container {
      min-height: calc(100vh - #{$top-nav-height} - #{$footer-height});
    }
    

    这不是一个完美的解决方案,因为它不会将页脚完全放在视口的底部,但当内容太短时,它会将页脚向下推到底部,并防止页脚在屏幕中间向上移动

    如果有人再次陷入这种困境

    HTML:

    CSS:


    材料设计引导有一个很好的类:。这是我用的

    在页脚自动设置父项在底部的位置后,需要设置父项的高度


    如果出现此问题后无法在父div或页脚部分添加内容或高度。

    只需使用flex-box:将主体显示设置为flex,然后将页脚与flex-end对齐即可。这样,页脚将始终是末尾的最后一个组件

    正文{
    显示器:flex;
    弯曲方向:立柱;
    }
    页脚{
    自对准:柔性端;
    
    }
    固定页脚与始终在页面底部显示页脚之间有什么区别?我的回答解决了您的问题吗?@showdev固定页脚有粘性。页面底部表示页脚下方没有div,但如果向上滚动,它并不总是在那里。这是一个很好的例子。请为链接添加上下文。我实现了这个代码,如果内容不占用整个视口,页脚仍然停留在页面的中间。是否有任何例外情况,我可能需要知道,以实现这一点?是的,差不多。此页脚css可以应用于任何内容<代码>页边距底部:0px
    或仅
    bottom:0px
    将起作用,但如果希望标题始终位于顶部,可以使用
    top:0px
    完成。它可以应用于任何东西,使用此标签
    左、右、上、下或边距-[position]
    其中
    位置
    =左、右、上或下。我想你应该提到@Scott以避免重复问题。干得好:DBe一定不要像我一样,不小心写了
    body{min height:100%}
    它不起作用,以防你感到奇怪。
    body {
        background: #ffffff none repeat scroll 0 0;
        padding:40px 0;
    }
    header{
      position:fixed;
      top:0;
      z-index:999;
      left:0;
      width:100%;
      background:#fff;
      border-bottom:1px solid #ccc;
    }
    header ul li {
      display: inline-block;
      list-style: outside none none;
      padding: 5px;
    }
    header ul li a {
        color: #000000;
        text-decoration: none;
    }
    footer {
      bottom: 0;
      left: 0;
      position: fixed;
      text-align: center;
      width: 100%;
      z-index: -1;
    }
    footer h1 {
      margin: 0;
    }
    .wrapper {
      background: #ffffff;
      padding: 0 15px;
      z-index: 1;
    }
    
    html {
      position: relative;
      min-height: 100%;
    }
    body {
      /* Margin bottom by footer height */
      margin-bottom: 60px;
    }
    .footer {
      position: absolute;
      bottom: 0;
      width: 100%;
      /* Set the fixed height of the footer here */
      height: 60px;
      background-color: #f5f5f5;
    }
    
    <footer class="footer">
    
    </footer>
    
    <body>
        <div class="top-nav">My Nav Bar</div>
        <div class="main-container">
            All my content
        </div>
        <div class="footer">
            My footer
        </div>
    </body>
    
    .top-nav {
        height: 4rem;
    }
    .main-container {
        min-height: calc(100vh - 4rem - 4rem);
    }
    .footer {
        height: 4rem;
    }
    
    .main-container {
      min-height: calc(100vh - #{$top-nav-height} - #{$footer-height});
    }
    
    <div class="demo">
      <h1>CSS “Always on the bottom” Footer</h1>
    
      <p>I often find myself designing a website where the footer must rest at the bottom of the page, even if the content above it is too short to push it to the bottom of the viewport naturally.</p>
    
      <p>However, if the content is taller than the user’s viewport, then the footer should disappear from view as it would normally, resting at the bottom of the page (not fixed to the viewport).</p>
    
      <p>If you know the height of the footer, then you should set it explicitly, and set the bottom padding of the footer’s parent element to be the same value (or larger if you want some spacing).</p>
    
      <p>This is to prevent the footer from overlapping the content above it, since it is being removed from the document flow with <code>position: absolute;</code>.</p>
    </div>
    
    <div class="footer">This footer will always be positioned at the bottom of the page, but <strong>not fixed</strong>.</div>
    
    /**
     * Demo Styles
     */
    
    html {
      height: 100%;
      box-sizing: border-box;
    }
    
    *,
    *:before,
    *:after {
      box-sizing: inherit;
    }
    
    body {
      position: relative;
      margin: 0;
      padding-bottom: 6rem;
      min-height: 100%;
      font-family: "Helvetica Neue", Arial, sans-serif;
    }
    
    .demo {
      margin: 0 auto;
      padding-top: 64px;
      max-width: 640px;
      width: 94%;
    }
    
    .demo h1 {
      margin-top: 0;
    }
    
    /**
     * Footer Styles
     */
    
    .footer {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      padding: 1rem;
      background-color: #efefef;
      text-align: center;
    }