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

Displaying or concealing HTML elements using AngularJS while a modal is open

Looking for a way to display a loading spinner icon on my page when a user triggers a button that opens a modal, and then have the spinner disappear once the modal is open and its content has loaded. Currently, I've managed to make the spinner show up ...

Updating the content within a div following the submission of a contact form 7

I'm struggling with my contact form. I want the content of my contact form div to change after clicking submit on the form. I've been searching for a solution, but so far, no luck. Here is what I have: Form (div1) with input fields, acceptance c ...

Is there a way to customize the color of a MUI styled component?

I have a customized MUI component that displays a circular badge in green. const StyledGreenBadge = styled(Badge)(({ theme }) => ({ '& .MuiBadge-badge': { backgroundColor: '#44b700', color: '#44b700', ...

Is it feasible to transition a mobile webpage seamlessly without using jqm?

I'm currently developing a Phonegap app and I am trying to steer clear of jqm in my project. I find that the css is causing some issues with the html code. As a workaround, I can transition between pages using: window.location = "profiles.html"; How ...

Difficulty in arranging DIVs on a flat surface

As a user running Win XP with Firefox, IE, and Google Chrome browsers, I'm encountering an issue where I can't seem to align two DIVs on the same horizontal plane. My goal is to have the left div occupy 24% of the screen width while the right div ...

Issue encountered when concealing page elements followed by revealing them again

My goal is to conceal an id within a page and then reveal it once all the JavaScript has finished loading on the page. The JavaScript I am using to display the content again is: $(document).ready(function() { $("#HomePage")[0].style.visibility = "visib ...

Differentiate between minimum and maximum values on ion-range sliders with discrete color options

I am currently working on customizing the theme of my ionic app, specifically trying to assign different colors to the min and max knobs on an ion-range component. At the moment, I am only able to apply a single HTML property called "color" to the selector ...

What is the best way to duplicate several HTML input fields using jQuery?

My div is quite intricate with input fields structured like this <input type="text" name="firstname"> <input type="text" name="lastname"> <input type="text" name="email"> <input type="text" name="address"> <div id="section_toC ...

Chrome has some issues with resizing the SVG Pattern element

Utilizing inline svgs, I have a svg circle filled with a pattern that should cover 100% of the container size. However, when the parent element is resized via JavaScript, the pattern no longer reflects the 100% width and height as expected. This issue seem ...

Steps for creating a resizable and automatically hiding side menu

I am working on a side menu that can be resized, and I want it to collapse (set to zero width) when it is empty. I have considered implementing one of these features individually, but I'm not sure how to make both work together. Is there a way to ad ...

Prevent user scrolling when full-screen menu is activated

Currently, I am developing a full-screen menu for a website and facing an issue with disabling the user's ability to scroll when the menu is open. Despite searching online, I have not found a suitable solution. It would be greatly appreciated if someo ...

Chrome stack router outlet and the utilization of the Angular back button

I'm experiencing an issue with the back button on Chrome while using Angular 14. When I return to a previous page (URL), instead of deleting the current page components, it keeps adding more and more as I continue to press the back button (the deeper ...

Tips for choosing a particular list item using jQuery: retrieve the attribute value of 'value' and showcase it on the webpage

I have a task that requires the following: Implement an event listener so that when you click on any list item, the value of its "value" attribute will be shown next to this line. In my HTML, I have an ordered list with 8 list items. The values range fro ...

Creating React components with scoped CSS imports

I am facing an issue with my component's CSS structure and import method. About/style.css .AboutContainer { # Some style } p > code { # Some style } When importing the CSS in the component: About/index.js import './style.css&apos ...

What is the best way to ensure uniformity in my boxes (addressing issues with whitespace and box-sizing using flexbox)?

Below is the code I have written: body { padding-top: 20px; text-align: center; background-color:black; } h1 { display: inline-block; background: white; } h1 { font-size: 30px } p { background: yellow; } .container { display: flex; ...

How to automatically select the first item in a populated dropdown list using Vue JS

My HTML select element is populated with options from a server, but when using v-model, it initially selects an empty option instead of the first one. I came across a solution on a post which suggests selecting the first option manually, but since the dat ...

Integrating a fresh element into the carousel structure will automatically generate a new row within Angular

I'm currently working on an Angular4 application that features a carousel displaying products, their names, and prices. At the moment, there are 6 products organized into two rows of 3 each. The carousel includes buttons to navigate left or right to d ...

Angular - Display shows previous and current data values

My Angular application has a variable called modelResponse that gets updated with new values and prints them. However, in the HTML, it also displays all of its old values along with the new ones. I used two-way data binding on modelResponse in the HTML [( ...

Is there a way to refresh a webpage without the need to reload it

Imagine a scenario where a tab on a website triggers the loading of a specific part of the webpage placed within a div. For example, clicking on a tab may trigger the loading of a file named "hive/index.php". Now, if a user selects an option from an auto ...

Arranging various s:select dropdowns for inline display styling

I have a form with three consecutive struts2 tags. Upon rendering the page, the s:select tag is automatically converted to the HTML code at the bottom. The issue arises when I attempt to style the form in order to display these dropdowns horizontally. Unf ...