What method does Apple use to apply overflow:hidden to elements within position:fixed?

After conducting my own experiments and delving into the topic online, I discovered that elements using position: fixed do not adhere to the overflow: hidden property of their parent element. This also applies to children within the fixed positioned element as they too ignore the ancestor's overflow: hidden property.

Surprisingly, Apple seems to have found a way around this on Apple Music.

Container with overflow: hidden

https://i.stack.imgur.com/VKfZU.png

Inner element with position: fixed

https://i.stack.imgur.com/ZU18Y.png

The device itself

https://i.stack.imgur.com/W5uhX.png

In the second image where there is a blue highlighted area, you can see that the fixed positioned element overflows its container along with the phone inside it (as shown in the third image). Despite this overflow, the contents of the fixed positioned element (the phone) are still truncated by the ancestor with an overflow: hidden property. If I remove the overflow: hidden property from the ancestor using Chrome's dev tools, the entire phone becomes fully visible.

How has Apple achieved this? I have attempted to recreate it using the same combination of fixed, relative, overflow properties, among other settings but without success, indicating that something crucial eludes me.

UPDATE

As elucidated by @user3790069 in his response, a fixed positioned element may be clipped by a relatively positioned one if the latter boasts a higher z-index, or it is simply located after the fixed positioned element (thus automatically assigned a greater z-index). Nonetheless, in the case of the Apple Music example, it appears that the overflow: hidden property continues to play a pivotal role for them. To confirm this, I eliminated several DOM elements to minimize clutter. The following screenshots showcase:

a) a wrapping section element incorporating overflow: hidden b) nested within it, a position: fixed element.

In the initial screenshot, note how the phone is cropped. Contrastingly, in the subsequent screenshot I withdrew the overflow: hidden property, thereby unveiling the overflowing segment of the phone.

https://i.stack.imgur.com/NU8Gc.png https://i.stack.imgur.com/K2plb.png

Answer №1

Initially, let me clarify why fixed children are not affected by the CSS property overflow: hidden of their parent element. A child box B is only clipped by the overflow property applied to its ancestor A if A serves as the containing block for B. However, in the case of a fixed element, the containing block is not simply an ancestor; it encompasses the entire viewport.
It seems that the fixed elements on the mentioned page are not actually cut off by the overflow property; instead, they seem to be concealed beneath other positioned elements.

Here is an example:

<div id=cont>
  <div style="background: red">
    <div class=fixed></div>
  </div>
  <div style="background: yellow">
    <div class=fixed id=second></div>
  </div>
    <div style="background: green"></div>
</div>

#cont {
  height: 5000px
}

#cont > div {
  height: 200px;
  position: relative
}

.fixed {
  width: 100px;
  height: 100px;
  background: black;
  position: fixed;
  right: 20px;
  top: 20px
}

#second {
  top: 240px
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to define a margin according to the size of the device being used

I am working on an angular/bootstrap web app and need to set a left margin of 40px on md, xl, lg devices and 0px on sm device. I attempted to create a spacer in styles.scss like this: $spacer: 1rem; .ml-6{ margin-left:($spacer*2.5); } Then in my HTML, ...

Utilizing partials in EJS for efficient HTML tag insertion

(1)home.ejs without using partials https://i.stack.imgur.com/3ozQQ.png (2)the output includes html tag, head tag and body tag https://i.stack.imgur.com/1o9jy.png (3)when utilizing header.ejs as a partial in home.ejs including opening html and body ta ...

Switch classes while navigating within a div

My website has a sticky sidebar with a list of cars and their corresponding categories in a table: <ul class = "cars"> <li class=""><a href="javascript:void(0)" class="model" data-id="1"> BMW </a></li> ...... ...

Design an interactive quarter-circle using CSS styling

My goal is to create this element using CSS, however, the content inside needs to be dynamic. I initially attempted to use border-radius, but realized it is unable to achieve the desired outcome. If anyone has a solution or can offer assistance, I would g ...

How do you vertically span a grid element across 3 rows using Material UI?

This particular scenario may appear to be straightforward, but the official documentation of Material UI lacks a clear example on how to achieve this. Even after attempting to nest the grid elements, I encountered an issue where the grid element on the ri ...

Using the CSS property `absolute` can result in the input element shifting when entering text in Chrome

My grid layout is causing some issues with the search box placement. Whenever a user starts typing in the input box, it jumps to the other side of the page. After investigating, I realized that the culprit is the position: absolute property. Oddly enough, ...

Troubleshooting Problems with display:table and display:table-cell Alignment in Internet Explorer Versions 7 and 9

I have been struggling with the layout of a website that contains multiple columns. After extensive work, I believed I had everything properly aligned. Adobe BrowserLab seemed to confirm this, aside from various issues in IE6 and IE7 which I decided to ove ...

Retrieving information from CRM online utilizing the Web API

Recently, I developed a webpage to serve as a survey for end users to provide feedback on the helpdesk technician's performance in resolving tickets. The webpage was constructed using HTML, CSS, JS, and PHP. Currently, the page requires access to two ...

What is the method for adjusting the border color of an ng-select component to red?

I am having an issue with the select component in my Angular HTML template. It is currently displaying in grey color, but I would like it to have a red border instead. I have tried using custom CSS, but I haven't been able to achieve the desired resul ...

What strategies should be employed to manage data-driven input in this particular scenario?

In the process of creating a small webpage, I have designed 2 navigation panels - one on the left and one on the right. The leftNav panel contains a list of different flower names. While the rightNav panel displays images corresponding to each flower. A ...

Is there a way to dynamically refresh the options in a select dropdown using jQuery?

I'm facing an issue with updating the options in a select element. Here is how my current select element looks: <select id="productId"> </select> Below is the jQuery code I am using: ... if (data.success) { var items = []; $.ea ...

I am looking for guidance on the proper way to import MatDrawer and MatDrawerContainer in the app.module.ts file for an Angular

When attempting to implement a side nav using angular material and clicking on the toolbar icon, everything was functioning correctly until I encountered an error while trying to open the navbar: The error message displayed: Unexpected directive 'Ma ...

Is there a way to create a table with "cells that can be controlled individually" similar to the image provided using HTML and CSS?

I have been searching online for solutions on how to create a table similar to the one in this image, but so far I haven't had much luck. I attempted to use colspan, however, it didn't yield the results I was hoping for. Does anyone have any alt ...

Is It Better to Consider Angular Elements as Building Blocks or Encapsulated Components?

When it comes to using element directives, I have noticed Angular element directives being used in two distinct ways: 1. Block Level Components In this approach, the element is styled with display:block, essentially making the element itself the componen ...

Endless cycle of invoking functions in Angular.js

Issue with the template : <div class="container"> <h1>Process Definitions</h1> <table class="table table-stripped" > <tr> <td><strong>Name</strong></td> <td><strong>Id</st ...

What is the best way to eliminate the pause in my slideshow?

After spending a few hours working on this project, I've almost completed it. However, I'm facing an issue with the slideshow functionality. It seems to pause after cycling through all the images. Any suggestions on why this might be happening? ...

Bootstrap's Vertical Margin Concept

Is there a way to include margin or a line similar to the image below? [![Please refer to the accompanying image][1]][1] ...

Achieve a responsive layout by dynamically sizing child div elements to fill their parent container using percentage-based margins and

I'm having trouble getting the child divs to stretch to the parent, and I'm not sure if I need to specify a % width on #fullpage-content even though #middle is set to 76%. I seem to have forgotten... Would you like to check out this link where c ...

The form action now triggers the download of the PHP file instead of simply loading

I'm encountering an issue with the form on my website: <div class="searchBar"> <form action="searchDB.php" method="get"> <input type="text" class="searchBarInput" bdo dir="rtl" name="k"> <input type="image" cl ...