Alper
Alper

Reputation: 1

Force div to scroll if the text overflows HTML/CSS?

So I have a div tag to sort of draw boxes around various sections, and of course make actual sections.

In one of the sections, there is more text than can be held in the div tag, so I want to for the text within the div tag to have a scroll bar to make it so the text doesn't overflow outside of the box.

How would I do that?

Upvotes: 12

Views: 49662

Answers (2)

Emil
Emil

Reputation: 8527

Add width and height CSS properties to the div, as well as overflow:auto

If you add overlow:scroll, the scroll bars will be always visible.

If you want to have only horizontal scroll, add white-space:nowrap to the element inside of the div.

Upvotes: 23

fletom
fletom

Reputation: 2028

Use the following:

div {
    overflow: scroll;
}

If you want them to scroll only in one direction, you can use the overflow-x and overflow-y properties.

Upvotes: 29

Related Questions