Position fixed with transform (behavior exploration)

Hi everyone. For the last 2 days I have been tinkering with this 'unknown behavior' where If I used transform to a container, the fixed position inside it would no longer work. The only way I managed to 'fix' this is by moving the element outside the container but that comes with a set of different problems such as breaking the layout and so on. If you have a better approach to this, I would love to see it. Thank you in advance, Ylli. (codepen for a simple illustration) https://codepen.io/yesm4n/pen/PoLpKxL
8 Replies
Mannix
Mannix5mo ago
MDN Web Docs
position - CSS: Cascading Style Sheets | MDN
The position CSS property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final location of positioned elements.
Mannix
Mannix5mo ago
according to mdn using tranform changes the containing block
Ylli
Ylli5mo ago
@Mannix ok, thats interesting. Glad you found that. Will have to explore more and see if I can do something to 'make as little changes as possible'. In any case, thank you sir.
clevermissfox
clevermissfox5mo ago
There are some properties that change the containing block. As you’ve seen transform is one of them, opacity is another. Trying to remember the others
Kevin Powell
Kevin Powell5mo ago
it's a bit annoying, for sure, because some things that create a new containing block won't impact fixed elements, whereas other things will. I will ask though, why taking it out of that element breaks the layout though. Normally we use fixed because we want it fixed to the viewport, and not in flow with the other things... Maybe position: sticky; is what you're after?
Ylli
Ylli5mo ago
A bit hard to explain and I can't disclose all the layout here because it is a confidential website but I'd be willing to show you over a dm. BUT basically – – I have a loading screen (which after 3 seconds) a container (with 6 sections in it moves up). – My first section (from the ones who just moved up) has the navbar in it and is not allowing me to stick/fix the navbar to the containers that got pulled up because of the transform behavior. So instead of creating 6 separate navbars, I thought I could find a way to just drag the 1st one around, but so far I've been unsuccessful. And as for the record sticky only follows me 1 section, whereas fixed does not even move.
Kevin Powell
Kevin Powell5mo ago
The only thing I can think of would be using position: sticky, but having the nav be a part of the entire container that has the 6 sections, and not inside the first section itself.
Ylli
Ylli5mo ago
I see, that makes sense. Will probably opt for that since I can't seem to find a better solution so far. Thank you Kevin.
Want results from more Discord servers?
Add your server
More Posts
Adding an dataset attribute to rendered div of mat-tab from Angular MaterialI want to add a dataset attribute on tab indicator div rendered by mat-tab component for label. HereResponsive container : max-width or padding ?Hi, When I create a website, I usually use ` <section class="container"></section> ` and `.contaiReact router dom is not redirecting to the route even though the url is changedHey I am facing a error. when I try to log in with my admin account on a website I am working in. ThSeeking Assistance: Centering Issue with Flexbox HeaderHi, I hope you all are doing well. I am writing code for a little design. However, I am facing an iJumping for characterHello, I am having an issue with making a jumping animation for my character. Here is the code: ```Can some review my attempt at this coding challenge?I deployed it on GitHub pages This is the URL. https://davesamuels1998.github.io/Newsletter-sign-up-overflowing text in grid areacurrently trying to troubleshoot this one: I have a grid of columns, where each item is a grid of immax-width media query not applying to max valueI have an odd issue where my max-width media query; eg: `@media (max-width: 1023px)` is working on e[React] How does this code look to you?Friend and I spent a few hours yesterday trying to get setInterval and useEffect to work on our littI have the following code how I can make contaniner_contant class closer to background_countainerin the following code https://codesandbox.io/p/sandbox/layout-page-8gvxls you can see there space