There are other values that control how overflow content behaves. To hide overflowing content use a value of hidden
. This may cause some of your content to not be visible.
Using a value of scroll
contains the content in its box and add scrollbars to enable viewing it. Scrollbars will be added even if the content fits in the box.
Using a value of auto
will display the content with no scrollbars if the content fits inside the box. If it doesn't fit then scrollbars will be added. Comparing the next example with the example for overflow: scroll
you should see overflow scroll
has horizontal and vertical scrollbars when it only needs vertical scrolling. The auto
example below only adds the scrollbar in the direct we need to scroll.
As we have already learned, using any of these values, other than the default of visible,
will create a new Block Formatting Context.
Note: In the Working Draft of Overflow Level 3, there is an additional value overflow: clip
. This will act like overflow: hidden
however it does not allow for programmatic scrolling, the box becomes non-scrollable. In addition it does not create a Block Formatting Context.
The overflow property is in reality a shorthand for the overflow-x
and overflow-y
properties. If you specify only one value for overflow, this value is used for both axes. However, you can specify both values in which case the first is used for overflow-x
and therefore the horizontal direction, and the second for overflow-y
and the vertical direction. In the below example, I have only specified overflow-y: scroll
so we do not get the unwanted horizontal scrollbar.