Div at bottom of window and adaptable height div

て烟熏妆下的殇ゞ 提交于 2019-12-18 17:27:52

问题


Is there a way to get a div to always be at the bottom of the window, and another div to change its height to fill any space that it leaves, and that div will scroll if its content is too long. (I never want the window to scroll).

This is best illustrated by a picture:

div layout http://img401.imageshack.us/img401/3209/divs.png

The green div will always put itself at the bottom of the window, and the orange div will fill the gap. When the window is smaller, like in the right hand image, the orange div will be smaller and will scroll.

The green div can be toggled. Sometimes the green div will have display: none, and then the orange div will stretch to the bottom. When the green div has display: block again, it will look like the picture again.

It has to work in IE6.

So far I can get the green div to go to the bottom by:

position: absolute;
bottom: 0;

But I don't know how to get the orange div to do what I want.


回答1:


you can take a look at "Exploring Footers" at A List Apart,

http://www.alistapart.com/articles/footers/

hope it helps, Sinan

EDIT: (pure CSS way)

Your Markup:

<div class="non-footer">Your content goes here.</div>
<div class="footer">Here is for footer content.</div>

Your CSS:

body, html, .non-footer {
    height: 100%;
    min-height: 100%;
    width: 100%;
}
.footer {
    height: 150px;
    margin-top: -150px;
    width: 100%;
}

I might be missing some details, but this should work and it gives the basic idea behind the trick.

Sinan.




回答2:


you should use fixed instead of absolute

position: fixed;
bottom: 0;



回答3:


Test this. Put this in the head:

<script>
    var int=self.setInterval(function(){clock()},100);

    function clock()
    {
        var s = document.getElementById("Footer");
        s.style.position = "Fixed";
        s.style.bottom = "0px";
        s.style.margin = "0px";
        s.style.height = "20px";
        s.style.width = "30px";
    }

    window.onload=clock
</script>

The html:

<div id="Footer"></div>



回答4:


try this: set the orange div position relative with a bottom margin = height of the green div with an overflow: auto

I think your orange div will then scroll if it becomes larger then the space between the white and green div. to solve your background problem, you can easily set orange as background color. In that way, it will never be visible for a user that your orange div is in fact smaller as the space between the white and green divs




回答5:


I don't think this is possible without working out the size of the centre div using Javascript.

CSS positioning basically flows from the top down, so to get a div to stick at the bottom of the page you need to take it out of the flow of the page using position:absolute (or position:fixed)

But now that div is out of the flow of the page, so the middle div doesn't know to stop at the top of the bottom div. It will just carry on behind the bottom div and won't display scrollbars.




回答6:


You can use the following solution to get the orange div to do what you want:

if ( ( $('.container-with-footer').height() ) < ( $(window).height() ) ) {
    $('footer').css({
        "position":"absolute",
        "left":"0",
        "right":"0",
        "bottom":"0"
    })
}


来源:https://stackoverflow.com/questions/1347366/div-at-bottom-of-window-and-adaptable-height-div

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