Home > Web Front-end > CSS Tutorial > How to Create a Vertically Scrollable Div with CSS?

How to Create a Vertically Scrollable Div with CSS?

Susan Sarandon
Release: 2024-12-16 02:49:08
Original
796 people have browsed it

How to Create a Vertically Scrollable Div with CSS?

Vertical Scrolling Div with CSS

Question:

How can I create a div that is only scrollable vertically using CSS?

Answer:

To vertically scroll a div, it is important to specify the overflow property with the correct value.

The syntax for overflow is as follows:

overflow: <value>;
Copy after login

Where can be:

  • visible: No scrollbars are displayed, even if the content overflows the div.
  • hidden: Scrollbars are displayed only when the content overflows the div.
  • scroll: Scrollbars are always displayed, even if the content does not overflow the div.
  • auto: Scrollbars are displayed only when the content overflows the div in the specified direction.
  • inherit: Inherits the overflow property from the parent element.

For vertical scrolling only:

  • Use overflow-y: scroll; to force a vertical scrollbar to appear, regardless of whether the content exceeds the height of the div.
  • Use overflow-y: auto; to display a vertical scrollbar only if the content overflow the height of the div.

For example, to create a div that is 400px high and only scrollable vertically:

<div>
Copy after login

The above is the detailed content of How to Create a Vertically Scrollable Div with CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template