Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yet another div height question

Tags:

html

css

Over the years, I've struggled with this. This year, there might be a solution. I need a header, content and footer. I would like the footer to be at the bottom of the page, the header at the top, and the content in between.

I would like the content to have a scroll bar.

Q: Is that too much to ask?

like image 872
Phillip Senn Avatar asked Nov 25 '25 21:11

Phillip Senn


2 Answers

If the header and footer have fixed heights:

<style type="text/css">
    #header {
        height: 100px;
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        background-color: red;
    }
    #footer {
        height: 100px;
        width: 100%;
        position: absolute;
        left: 0;
        bottom: 0;
        background-color: green;
    }
    #content {
        width: 100%;
        position: absolute;
        left: 0;
        top: 100px;
        bottom: 100px;
        overflow: auto;
        background-color: blue;
    }
</style>

<body>
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
</body>
like image 180
Anton Avatar answered Nov 28 '25 09:11

Anton


I'm not entirely sure whether this really answers your question but the property for getting a scroll bar if necessary (i.e. if a container's content exceeds its size) is

overflow: auto

there are selective properties for horizontal and vertical scroll bars:

overflow-x: auto;
overflow-y: auto;

but they are part of the CSS 3.0 specification and only supported by a limited number of browsers (namely Firefox > 1.5, Opera and Safari).

like image 24
Pekka Avatar answered Nov 28 '25 10:11

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!