2011-04-28 36 views
1

如果内容大于一页,我正在寻找将页脚设置为页面结尾或内容结束的可能性。 我不想有一个固定页脚的内容是可滚动的。 我不知道这是否可能。将页脚设置为内容或页面结尾

所以,这是我的代码。 class =“div1”的div包含内容。 内容包含内容以及页脚。


<div class="div1"> 
    <div class="content"> 
     <div class="myContent"></div> 
     <div class="myContent"></div> 
     <div class="myContent"></div> 
     <div class="footer"></div> 
    </div> 
</div> 

页脚的高度为50px。 我的问题如下: 如果我有一个屏幕高度:500px,内容只有150px高,页脚被设置在class =“myContent”的最后一个div元素之后。 它应该设置为页面的结尾,就像我通过

 
bottom:0;position:fixed
收到的效果一样。但是,如果内容高度为600px,则应该在class =“myContent”的最后一个div后面设置页脚。这里不需要任何样式。

你知道如何解决它吗?

回答

1

你的意思是Make the Footer Stick to the Bottom of a Page? 或本one

的CSS

html, body {height: 100%;} 

#wrap {min-height: 100%;} 
#main {overflow:auto; 
padding-bottom: 150px;} /* must be same height as the footer */ 

#footer {position: relative; 
margin-top: -150px; /* negative value of footer height */ 
height: 150px; 
clear:both;} 

和HTML

<div id="wrap"> 

    <div id="main"> 

    </div> 

</div> 

<div id="footer"> 

</div> 
+0

+1。我确实相信她的确如此。这是一篇很好的文章。 – 2011-04-28 13:10:56

+0

嗨,对不起,我迟到了。不幸的是我的html是不同的。 :-(footer div在主div中,你的例子在我的情况下不起作用......这就是我问的原因。 – judi55 2011-04-28 15:44:07

+0

然后将你的页脚移出主界面或者创建一个新的div。这是你需要改变它以满足你的确切需要的一个例子 – yossi 2011-04-28 17:26:17

1

我想这可能会帮助你摆脱掉这个问题:

.footer {position:absolute;left:0;right:0;bottom:0;background:green;height:50px} 

这样可以解决目标:

<div style="position:absolute"> 
    <div style="position:absolute"> 
     <div id="top" style="height:50px;width:100%;position:fixed;left:0;top:0;background:red"> content 1 </div> 
     <div id="middle" style="background:green;position:fixed;top:50px; left:0;bottom:50px;right:0">content 2 </div> 
     <div id="middle" style="background:blue;position:fixed;top:100px; left:0;bottom:50px;right:0">content 3 </div> 
     <div id="bottom" style="height:50px;width:100%;position:fixed;left:0;bottom:0;background:orange">Footer</div> 
    </div> 
</div> 
+0

嗨,它不工作,因为有人已经设置了位置:在父母divs绝对 - 在某个地方,谢谢你,这是值得一试 – judi55 2011-04-28 15:48:46

+0

@ judi55大家好,请检查一下新的答案,如果没有,请评论我有什么问题,在这里,我为所有父'div'使用'position:absolute',如果任何一个'div'具有'position:absolute “我认为这也会起作用。 – thecodeparadox 2011-04-30 08:36:53