【问题标题】:sticky footer inside tow div拖车div内的粘性页脚
【发布时间】:2016-09-29 07:23:45
【问题描述】:

我正在尝试制作一个始终位于底部的粘性页脚。但我的页脚不是第一个 div 的直接子元素,它是第二个子元素。赞这个https://jsfiddle.net/bduswush/

<div id="outer-wrap">
    <div id="inner-wrap">
        <div class="head">This is head</div>
        <div class="content">This is body</div>
        <div class="footer">This is footer</div>
    </div>
</div>

但问题就在这里——它没有占据设备屏幕的整个高度,并且内容 div 与页脚重叠。我想将页脚高度自动保留。有什么解决办法吗??提前致谢。

【问题讨论】:

    标签: html css


    【解决方案1】:

    您必须将height 和width 设置为html 和body 标签。

    html,body{
      height: 100%;
      width: 100%;
      border: 0;
    }
    

    html,body{
      height: 100%;
      width: 100%;
      border: 0;
    }
    #outer-wrap {
    	height: 100%;
      background: #ccc;
    }
    #inner-wrap {
    	min-height: 100%;
    	position: relative;
      background: #00b;
    }
    .footer {
    	position: absolute;
    	bottom: 0;
    	width: 100%;
      background: red;
    }
    <div id="outer-wrap">
    		<div id="inner-wrap">
    			<div class="head">This is head</div>
    			<div class="content">This is body</div>
    			<div class="footer">This is footer</div>
    		</div>
    </div>

    这是因为当您将height 和width 与百分比一起使用时,它会从其父级获取其值,因此如果您不为其父级的height 和width 设置值,则无法填充需要空间。

    【讨论】:

    • 确实height,但为什么width?
    • @Pepo_rasta 我总是在 html 和 body 标签上设置它以获得完整的可用空间。然后,如果我需要较低的宽度,我会设置一个容器来包装它。只是个人习惯。
    • 这在 PC 上效果很好,但是当我使用移动设备时,我无法向下滚动我的内容,因为 #outer-wrap 固定为 100%。
    • @aziz 尝试使用min-height: 100%。
    • 真的很抱歉兄弟,它现在可以在移动设备中使用,但在 PC 中可以使用;它位于内容的正下方,而不是设备屏幕的底部。请大哥查一下。非常感谢您,因为您为我浪费了宝贵的时间。
    猜你喜欢
    • 2013-02-23
    • 1970-01-01
    • 2014-02-13
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 2012-06-02
    相关资源
    最近更新 更多