2

I want to add div to my website which has variable width, and that it will display scroll bars when the width is smaller than the longest line. I tried wrapping such a fixed width element, in a variable width (100%) but that didn't work. I got the scroll bars on the entire page.

Any thoughts?

Thanks Yaron

Yaron
  • 2,053
  • 2
  • 19
  • 21

1 Answers1

0

You can apply the overflow CSS property to the problematic div:

#problematic-div {
    overflow: hidden;
}

This defines what happens to content that overflows the content area of an element. For the value scroll, user agents are supposed to provide a scrolling mechanism whether or not it is actually needed; thus, for example, scrollbars would appear even if all content can fit within the element box.

You can try some examples here.

Hope it helps.

Diosney
  • 10,520
  • 15
  • 66
  • 111
  • This doesn't really help, as it doesn't show the scroll bars for that div, just hides the overflow. – Yaron Aug 29 '11 at 08:59
  • @Yaron: Just for clarification, what you want is to show the scroll bars when the inner elements are greater than the parent div width and hide it otherwise? – Diosney Aug 29 '11 at 14:48