Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position fixed not working is working like absolute [closed]

Tags:

css

my question is pretty simple. I'm working on a page on mobile version, and we want to keep the "snag it" yellow button fixed on bottom, but position fixed is not working, it's working like position absolute and i don't know why.

The page i'm working: https://www.thechivery.com/products/everything-is-j-ok-tee

Thanks, Luiz

like image 249
Luiz Mitidiero Avatar asked Apr 26 '16 04:04

Luiz Mitidiero


People also ask

Why is my position Fixed not working?

Position fixed doesn't work with transform CSS property. It happens because transform creates a new coordinate system and your position: fixed element becomes fixed to that transformed element. To fix the problem you can remove transform CSS property from the parent element.

Does position absolute work with position fixed?

Absolutely positioned elements are positioned with respect to a containing block, which is the nearest postioned ancestor. If there is no positioned ancestor, the viewport will be the containing block. Elements with fixed positioning are fixed with respect to the viewport—the viewport is always their containing block.

How do absolute relative and fixed position differ?

Static - this is the default value, all elements are in order as they appear in the document. Relative - the element is positioned relative to its normal position. Absolute - the element is positioned absolutely to its first positioned parent. Fixed - the element is positioned related to the browser window.

How does the absolute positioning work?

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.


2 Answers

The issue here lies with your .content-container wrapper class, which has a CSS declaration of webkit-transform: translate3d(0,0,0). The transform declaration, as this answer illustrates, changes the positioning context from the viewport to the rotated element, which essentially means that your fixed element behaves as if it were absolutely positioned. Here's an example showing the difference between a fixed element inside a transformed div and a fixed element outside of that div.

.rotate {    transform: rotate(30deg);    background: blue;    width: 300px;    height: 300px;    margin: 0 auto;  }  .fixed {    position: fixed;    background: red;    padding: 10px;    color: white;    top: 50px;  }
<div class="rotate">    <div class="fixed"> I am fixed inside a rotated div.</div>  </div>  <div class="fixed"> I am fixed outside a rotated div.</div>

In order for everything to work, you'll need to remove the transform3d declaration from .content-container.

like image 120
litel Avatar answered Sep 17 '22 13:09

litel


For anyone wondering if this is a browser bug. Apparently it's not and it follows current W3C specs. What's strange is at first it was just inconsistent between the browsers (in some it worked as intended) and then all of them started to follow the counter intuitive W3C rules. There seems to be no clear explanation if this is actually intended logic, a side effect of some implementation problem or just a dumb omission.

Also position: fixed gets broken not only by transform but also by filter and perspective property put on any ancestor as explained here.

See: https://www.w3.org/TR/css-transforms-1/#propdef-transform and https://www.w3.org/Bugs/Public/show_bug.cgi?id=16328 and https://github.com/w3c/csswg-drafts/issues/913 for more info on this issue.

like image 24
konrad Avatar answered Sep 21 '22 13:09

konrad