开发者

Creating a variable width <pre> element with optional scrollbars

开发者 https://www.devze.com 2023-03-29 11:25 出处:网络
I want to adddiv to my website 开发者_如何学Gowhich has variable width, and that it will display scroll bars when the width is smaller than the longest line.

I want to add div to my website 开发者_如何学Gowhich 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号