Overflow Property in CSS

  • In CSS, the `overflow` property is used to control how content that exceeds the dimensions of an element is handled. It specifies whether to clip, display scrollbars, or automatically expand the element to accommodate the overflowing content.
  • The `overflow` property can be applied to block-level elements (such as `<div>` or `<p>`) and replaced inline-level elements (such as `<img>` or `<video>`).
Here are the available values for the `overflow` property:
  • visible (default): Content overflows the element's boundaries without any clipping or scrollbars. This may cause the content to extend beyond the parent container.
  • hidden: Any content that exceeds the element's dimensions is clipped and not displayed. It is effectively hidden from view.
  • scroll: Scrollbars are always shown, regardless of whether there is overflow or not. If the content exceeds the element's dimensions, the scrollbars allow users to scroll and view the hidden content.
  • auto: Scrollbars are displayed only when necessary. If the content fits within the element's dimensions, no scrollbars are shown. If the content exceeds the dimensions, scrollbars appear to allow scrolling.
  • It's important to note that the `overflow` property only affects the visible rendering of content within an element. It does not affect the actual dimensions or positioning of the element itself.

Here's an example usage of the `overflow` property in CSS:


    div {
        width: 200px;
        height: 200px;
        overflow: scroll;
         border: 2px solid black;
    }

  • In this example, a `<div>` element with a fixed width and height of 200 pixels is specified. The `overflow` property is set to `scroll`, which will display scrollbars if the content within the `<div>` exceeds its dimensions.
  • Overall, the `overflow` property is a useful tool for controlling how overflowing content is handled within an element and can help create better user experiences when dealing with large or dynamically changing content.

No comments:

Post a Comment

Primitive Types in TypeScript

In TypeScript, primitive types are the most basic data types, and they are the building blocks for handling data. They correspond to simple ...