Skip to content

[css-overflow] allow elements to escape the scroll container #9107

@mayank99

Description

@mayank99

Problem/motivation

Currently, if an element is made into a scroll container (e.g. using overflow: auto or overflow: hidden), then nothing inside it can "escape" out.

It is often desirable for some parts to be able to escape. Consider three examples:

  • box-shadow often needs to protrude out of the container. Very common.
  • position: absolute is often used to make elements protrude out or be anchored near one of the edges. One use case is nested scrollable sub menus, demonstrated in the css-tricks article "Popping out of hidden overflow".
  • transform can be used to displace an element out of the container. Used in combination with display: grid (e.g. place-self: end), this is a great way to place decorative or functional elements near the corners of the containers.

In all of these examples, the element gets clipped if it tries to escape the scroll container.

Ideas

There could be a simple way to make an element not be constrained by the scroll container.

.scroll-container {
  overflow: auto;

  .escape {
    overflow-escape: x; /* or y or both */
  }
}

@daviddarnes suggested a more powerful idea, where an element could specify which scroll container it wants to (not) be constrained by.

.scroll-container {
  overflow: auto;

  .escape {
    overflow-container: none;
  }
}
.scroll-container {
  overflow: auto;
  container-name: one;
  contain: overflow;

  .another-scroll-container {
    overflow: auto;
    container-name: two;

    .escape {
      overflow-container: one;
    }
  }
}

Another idea that might solve some use cases would be to allow individual elements to control their own version of overflow-clip-margin.

.escape {
  /* will be clipped if it goes more than 20px outside the scroll container */
  overflow-escape-margin: 20px;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions