Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: position:fixed inside of position:absolute

I'm running into some extremely strange behaviors, and non-consistant across every browser i've tested.

I've a pretty complex layout, but the main issue lies here:

<div id="drop">   <div id="header"></div> </div> 

#drop has position:absolute and z-index:100
#header has position:fixed; top:60px;

As I start scrolling down Chrome ignores the position:fixed rule. If I remove either of the two styles above from #drop then Chrome starts respecting the position:fixed rule.

can't get it working on Ubuntu Chrome 23.0.1271.97 and see the same behavior on Mac Chrome 25.0.1364.99. My friend uses Ubuntu Chrome 25.0.1364.68 beta and it works correctly for him. I've tested it on firefox and it kinda works (with other symptoms)

Has anyone heard of this error? or can anyone even reproduce it?

edit

I'm using openlayers map as another div with position:fixed if I delete that layer or at least change it to display:none then this weird bug goes away.

edit

Noticed that during the presence of this bug, if I change the zoom level back and forth, then the position adjusts itself to the proper behavior. To me, this indicates a webkit issue that fails to execute some internal callback function on scroll.

Another extremely strange thing is that I have a few links inside of #header and they work if I just click the expected location, even though the the div does not appear there. Overall I've noticed that it's only the rendering that's broken. If at any point of time I force the browser to re-render by resizing the window, or changing zoom, or just doing Select-All, then the header bar jumps to the proper position, but does not remain fixed.

like image 977
Mikhail Avatar asked Mar 01 '13 07:03

Mikhail


People also ask

Does position absolute work with position fixed?

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.

How do you do position absolute and fixed?

It can be achieved using percentage widths or by using fixed widths and the setting a negative margin relative to the container width. A note about CSS positioning. Element is always positioned relative to the screen. Element is positioned relative to the nearest parent container with a position attribute.

How do you fix an element inside a div?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.


1 Answers

You mentioned in the comments that OpenLayers uses CSS transforms. That being the case:

the element with fixed positioning will become relative to the element with the transform - not relative to the viewport

Take a look at the spec: The Transform Rendering Model

Specifying a value other than ‘none’ for the ‘transform’ property establishes a new local coordinate system at the element that it is applied to.

.wpr  {      width: 200px;      height:1000px;      background: pink;      position:relative;      margin: 0 200px;      -webkit-transform: translateX(0);      transform: translateX(0);  }  .fixed  {      width: 200px;      height:200px;      margin: 50px;      position: fixed;          top:0;      left:0;      background: aqua;  }
<div class="wpr">      <div class="fixed"></div>  </div>
like image 92
Danield Avatar answered Sep 24 '22 11:09

Danield