tom
tom

Reputation: 21

HTML body height - fixed?

I'm trying to make the main body of my site to have a fixed height (I think!).

Anyway, the site body is just white, with a border of size 1. Basically, the size of the body is determined by what's in it so, for example, it will resize automatically as more things are added.

What I want is vertical scroll bars so the body doesn't extend forever (is that right?). Should I have a fixed body size?

Upvotes: 0

Views: 34563

Answers (4)

JakeParis
JakeParis

Reputation: 11210

If you want the vertical scroll bars to an inner div on your site (like so you can have a footer visible at all times), simple specify the height of the div:

#inner { max-height: 300px;
    }

I think the default for the overflow is to scroll, but if your content is cutting cut off with no scrollbars, you could also set

overflow: auto;

Upvotes: 0

Mohamad
Mohamad

Reputation: 35349

So, in your body create a layer:

<div id="mainbar">
</div>

And using CSS you can set the height:

div#mainbar {
    min-height:100px;
    overflow:auto;
}

The min-height guarantees the initial height that you need. Once it goes over that, it you will automatically have scrollbars. If you would rather the page itself scroll and the body lengthen, just take out the overflow line from the CSS.

Upvotes: 0

KyleWpppd
KyleWpppd

Reputation: 2030

Yes. You need a fixed height

body{
height: your-height;
overflow:auto;
}

will generate scroll bars only when you overflow the area without growing it vertically.

Upvotes: 0

goggin13
goggin13

Reputation: 7976

If you want vertical scroll bars you can use this in your CSS;

body {
   height: 900px;
   overflow-y: scroll;
   overflow-x: hidden; /* hides the horizontal scroll bar */
}

What are you trying to accomplish? You sound unsure if you even want the scroll bars; is there a reason you want to show the scroll bars instead of just having the browser handle the scrolling when the content gets larger than the window?

Upvotes: 2

Related Questions