CSS Layout - Overflow
- Previous Page CSS z-index
- Next Page CSS Floating
CSS overflow property controls how content that is too large to fit into the area is handled.
CSS Overflow
overflow
The property specifies whether the content is clipped or a scrollbar is added when the element's content is too large to fit into the specified area.
overflow
The property can be set to the following values:
visible
- Default. Overflow is not clipped. Content is rendered outside the element's boxhidden
- The overflow is clipped, and the remaining content will be invisiblescroll
- The overflow is clipped, and a scrollbar is added to view the remaining contentauto
- Withscroll
Similar, but only adds a scrollbar when necessary
Note:overflow
The property only applies to block elements with a specified height.
Note:In OS X Lion (on Mac), the scrollbar is hidden by default and only appears when used (even if 'overflow:scroll' is set).
overflow: visible
By default, overflow is visible (visible
), this means it will not be clipped but rendered outside the element's box:
Example
div { width: 200px; height: 50px; background-color: #eee; overflow: visible; }
overflow: hidden
If you use hidden
The value, the overflow will be clipped, and the remaining content will be hidden:
Example
div { overflow: hidden; }
overflow: scroll
If the value is set to scroll
The overflow will be clipped, and a scrollbar will be added to scroll within the box. Note that this will add a scrollbar in both horizontal and vertical directions (even if you do not need it):
Example
div { overflow: scroll; }
overflow: auto
auto
The value is similar to scroll
However, it only adds a scrollbar when necessary:
Example
div { overflow: auto; }
overflow-x and overflow-y
overflow-x
overflow-y
The property specifies whether the content's overflow is changed horizontally, vertically, or both:
overflow-x
Specifies how to handle the left/right edges of the content.overflow-y
Specifies how to handle the top/bottom edges of the content.
Example
div { overflow-x: hidden; /* Hide horizontal scrollbar */ overflow-y: scroll; /* Add vertical scrollbar */ }
All CSS Overflow Properties
Property | Description |
---|---|
overflow | Specifies what happens if the content overflows the element's box. |
overflow-x | Specifies how the left/right edges of the content are handled when the content overflows the element's content area. |
overflow-y | Specifies how the top/bottom edges of the content are handled when the content overflows the element's content area. |
- Previous Page CSS z-index
- Next Page CSS Floating