当前位置: 首页 > 工具软件 > Scroll Box > 使用案例 >

html5 div scroll,HTML Scrollbox

斜光耀
2023-12-01

HTML Scrollbox

This page contains HTML scrollbox code and examples. You can copy/paste this code into your website or blog.

What is an HTML Scrollbox?

An HTML scrollbox is basically a box with scrollbars. Usually the scrollbox is made using the HTML

tag and the scrollbars are defined using the CSS overflow property.

Although you could probably argue that an HTML textbox is a scrollbox - because it has scrollbars - on this page we will concentrate on the

type of scrollbox.

Scrollbox Example

Here's an example of a basic HTML scrollbox. Here, we use overflow:scroll to tell the browser to add scrollbars to the box (i.e. the

element).

Source CodeResult

This 'div' element uses 'overflow:scroll' to create scrollbars.

This 'div' element uses 'overflow:scroll' to create scrollbars.

Auto Scrollbars

In the above example we used overflow:scroll to add scrollbars to the box. Another option is to use overflow:auto.

By using overflow:auto, the box will only grow scrollbars if the contents are too big to fit inside. In other words, scrollbars will only appear when they're needed.

To demonstrate this, the following boxes use exactly the same code to define the scrollbox. The only difference between the two, is the size of their contents. The first box only has one small line of text, whereas, the second box has many lines of text - too many to fit inside the box. Therefore, the second box displays scrollbars and the first box doesn't.

First Box: Less Contents = No Scrollbar:

Source CodeResult

One small line of text.

One small line of text.

Second Box: More Contents = Scrollbar:

Source CodeResult

This 'div' element contains more content than the previous one. Because there's too much text to fit into the box, the box grows scrollbars.

This 'div' element contains more content than the previous one. Because there's too much text to fit into the box, the box grows scrollbars.

Scrollbox Color

You can change the color of your scrollboxes, their contents, and their scrollbars. Like this:

Source CodeResult

This 'div' element uses 'overflow:scroll' to create scrollbars whenever the contents of the 'div' become too large.

This 'div' element uses 'overflow:scroll' to create scrollbars whenever the contents of the 'div' become too large.

Here's more info about scrollbox color.

Scrollbox Border

You can change the color, style, and width of your scrollbox borders using the CSS border property. Example:

Source CodeResult

This 'div' element uses 'overflow:scroll' to create scrollbars whenever the contents of the 'div' become too large.

This 'div' element uses 'overflow:scroll' to create scrollbars whenever the contents of the 'div' become too large.

Here's more information about scrollbox borders.

 类似资料:

相关阅读

相关文章

相关问答