00 Votes

Scrollbar in DIV container

Question by Axuter | 2012-05-15 at 15:22

I want to make a scrollable area on my website with CSS or HTML.

I am using a DIV container, which should be 200x200 pixels in size and within this container, a content should be displayed, which can be larger than this area.

However, the DIV box should not be enlarged, if the content is bigger. Instead, scrollbars should appear at the edges of the DIV container, so that you can scroll the content. Is that possible somehow?

ReplyPositiveNegative
11 Vote

The CSS property, that you seek, is called "overflow". The overflow property requires a region, which height and width is defined. So in your case:

#scrollarea{
  width: 200px;
  height: 200px;
  overflow: scroll;
}

With overflow:scroll, both scrollbars will be always displayed. Instead, if you use overlow:auto, the browser decides individually, if scrollbars are needed or not. So you can, for example, achieve, that in a long text, only vertical scroll bars are displayed. Other features include overflow:hidden, with which the content is simply truncated, if it is too large, and overflow:visible, whereby the contents of the field are protruding whenever they are too big.

But for you, only the properties scroll or auto should be relevant, depending on whether the scrollbars should be displayed always or only when needed.
2012-05-15 at 20:16

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.