What is overflow html

overflow

The overflow CSS shorthand property sets the desired behavior when content does not fit in the parent element box (overflows) in the horizontal and/or vertical direction.

Try it

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

/* Keyword values */ overflow: visible; overflow: hidden; overflow: clip; overflow: scroll; overflow: auto; overflow: hidden visible; /* Global values */ overflow: inherit; overflow: initial; overflow: revert; overflow: revert-layer; overflow: unset; 

Values

Overflow content is not clipped and may be visible outside the element’s padding box. The element box is not a scroll container. This is the default value of the overflow property.

Overflow content is clipped at the element’s padding box. There are no scroll bars, and the clipped content is not visible (i.e., clipped content is hidden), but the content still exists. User agents do not add scroll bars and also do not allow users to view the content outside the clipped region by actions such as dragging on a touch screen or using the scroll wheel on a mouse. The content can be scrolled programmatically (for example, by setting the value of the scrollLeft property or the scrollTo() method), in which case. The element box is a scroll container.

Читайте также:  Return index html flask

Overflow content is clipped at the element’s overflow clip edge that is defined using the overflow-clip-margin property. As a result, content overflows the element’s padding box by the value of overflow-clip-margin or by 0px if not set. Overflow content outside the clipped region is not visible, user agents do not add a scroll bar, and programmatic scrolling is also not supported. No new formatting context is created. To establish a formatting context, use overflow: clip along with display: flow-root . The element box is not a scroll container.

Overflow content is clipped at the element’s padding box, and overflow content can be scrolled into view using scroll bars. User agents display scroll bars in both horizontal and vertical directions if only one value is set, whether or not any content is overflowing or clipped. The use of this keyword, therefore, can prevent scroll bars from appearing and disappearing as content changes. Printers may still print overflowing content. The element box is a scroll container.

Overflow content is clipped at the element’s padding box, and overflow content can be scrolled into view. Unlike scroll , user agents display scroll bars only if the content is overflowing and hide scroll bars by default. If content fits inside the element’s padding box, it looks the same as with visible but still establishes a new formatting context. The element box is a scroll container.

Note: The keyword value overlay is a legacy value alias for auto . With overlay , the scroll bars are drawn on top of the content instead of taking up space.

Description

Overflow options include hiding overflowing content, enabling scroll bars to view overflow content or displaying the content flowing out of an element box into the surrounding area, and combinations there of.

The following nuances should be kept in mind while using the various keywords for overflow :

  • Specifying a value other than visible (the default) or clip for overflow creates a new block formatting context. This is necessary for technical reasons; if a float intersects with a scrolling element, it would forcibly rewrap the content after each scroll step, leading to a slow scrolling experience.
  • For an overflow setting to create the desired effect, the block-level element must have either a set height ( height or max-height ) or white-space set to nowrap .
  • Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto .
  • The JavaScript Element.scrollTop property may be used to scroll through content in a scroll container, including when overflow is set to hidden .

Formal definition

  • overflow-x : as specified, except with visible / clip computing to auto / hidden respectively if one of overflow-x or overflow-y is neither visible nor clip
  • overflow-y : as specified, except with visible / clip computing to auto / hidden respectively if one of overflow-x or overflow-y is neither visible nor clip

Formal syntax

overflow =
[ visible | hidden | clip | scroll | auto ]

Examples

Demonstrating results of various overflow keywords

HTML

div> code>visiblecode> p class="visible"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> div> code>hiddencode> p class="hidden"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> div> code>clipcode> p class="clip"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> div> code>scrollcode> p class="scroll"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> div> code>autocode> p class="auto"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> div> code>overlaycode> p class="overlay"> Maya Angelou: "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel." p> div> 

CSS

body  display: flex; flex-wrap: wrap; justify-content: start; > div  margin: 2em; font-size: 1.2em; > p  width: 5em; height: 5em; border: dotted; margin-top: 0.5em; > div:nth-of-type(5), div:nth-of-type(6)  margin-top: 200px; > 
p.visible  overflow: visible; > p.hidden  overflow: hidden; > p.clip  overflow: clip; overflow-clip-margin: 1em; > p.scroll  overflow: scroll; > p.auto  overflow: auto; > p.overlay  overflow: overlay; > 

Result

Accessibility concerns

A scrolling content area cannot be scrolled by a keyboard-only user, with the exception of users on Firefox (which makes the container keyboard focusable by default).

As a developer, to allow non-Firefox keyboard-only users to scroll the container, you will need to give it a tabindex using tabindex=»0″ . Unfortunately, when a screen reader encounters this tab-stop, they will have no context for what it is and their screen reader will likely announce the entirety of its contents. Giving it an appropriate WAI-ARIA role ( role=»region» , for example) and an accessible name (via aria-label or aria-labelledby ) can mitigate this.

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

Источник

CSS Layout — Overflow

The CSS overflow property controls what happens to content that is too big to fit into an area.

This text is really long and the height of its container is only 100 pixels. Therefore, a scrollbar is added to help the reader to scroll the content. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.

CSS Overflow

The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area.

The overflow property has the following values:

  • visible — Default. The overflow is not clipped. The content renders outside the element’s box
  • hidden — The overflow is clipped, and the rest of the content will be invisible
  • scroll — The overflow is clipped, and a scrollbar is added to see the rest of the content
  • auto — Similar to scroll , but it adds scrollbars only when necessary

Note: The overflow property only works for block elements with a specified height.

Note: In OS X Lion (on Mac), scrollbars are hidden by default and only shown when being used (even though «overflow:scroll» is set).

overflow: visible

By default, the overflow is visible , meaning that it is not clipped and it renders outside the element’s box:

You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element’s box.

Example

overflow: hidden

With the hidden value, the overflow is clipped, and the rest of the content is hidden:

You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element’s box.

Example

overflow: scroll

Setting the value to scroll , the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it):

You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element’s box.

Example

overflow: auto

The auto value is similar to scroll , but it adds scrollbars only when necessary:

You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element’s box.

Example

overflow-x and overflow-y

The overflow-x and overflow-y properties specifies whether to change the overflow of content just horizontally or vertically (or both):

overflow-x specifies what to do with the left/right edges of the content.
overflow-y specifies what to do with the top/bottom edges of the content.

You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element’s box.

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 content overflows an element’s box
overflow-wrap Specifies whether or not the browser can break lines with long words, if they overflow its container
overflow-x Specifies what to do with the left/right edges of the content if it overflows the element’s content area
overflow-y Specifies what to do with the top/bottom edges of the content if it overflows the element’s content area

Источник

CSS overflow Property

The overflow property specifies what should happen if content overflows an element’s box.

This property specifies whether to clip content or to add scrollbars when an element’s content is too big to fit in a specified area.

Note: The overflow property only works for block elements with a specified height.

Default value: visible
Inherited: no
Animatable: no. Read about animatable
Version: CSS2
JavaScript syntax: object.style.overflow=»scroll» Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Note: In OS X Lion (on Mac), scrollbars are hidden by default and only shown when being used (even though «overflow:scroll» is set).

CSS Syntax

Property Values

Value Description Demo
visible The overflow is not clipped. It renders outside the element’s box. This is default Demo ❯
hidden The overflow is clipped, and the rest of the content will be invisible. Content can be scrolled programmatically (e.g. by setting scrollLeft or scrollTo()) Demo ❯
clip The overflow is clipped, and the rest of the content will be invisible. Forbids scrolling, including programmatic scrolling. Demo ❯
scroll The overflow is clipped, but a scroll-bar is added to see the rest of the content Demo ❯
auto If overflow is clipped, a scroll-bar should be added to see the rest of the content Demo ❯
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Источник

Оцените статью