Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css3 transform reverts position: fixed

Tags:

When using a css3 transform(), position: fixed does not apply. I made a fully working jsFiddle showing the issue: http://jsfiddle.net/SR5ka/

First scroll down, notice the left-hand sidebar stays fixed. Now, click expand, and scroll down, notice the left-hand sidebar is now not fixed.

Any idea if there is a native css fix for this?

like image 286
Justin Avatar asked Sep 27 '13 20:09

Justin


People also ask

Will change transform position fixed?

Effectively it means that by specifying will-change:transform you make the element transformed (though visually it stays in the same position), and descendants of the transformed elements can't be fixed per the CSS Transforms spec.

What is transform() in CSS?

The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.

What is the opposite of position fixed in CSS?

position:static; , position:absolute; , and position:relative; are the alternatives to position:fixed; . There isn't a definitive opposite, because relative , absolute , static , and fixed have different properties to behave differently.


1 Answers

You could use a work around like this one. It involves toggling a left value (via a class) for both the fixed element and the container.

.global-wrapper {     position: relative;     -webkit-transition: 300ms;     transition: 300ms; } .global-wrapper.expanded, .global-wrapper.expanded .navbar {     left: 200px; } .navbar {     -webkit-transition: 300ms;     transition: 300ms;     position: fixed;     width: 100px;     height: 100%;     top: 0px;     left: 0px; } .content {     position: relative;     width: calc(100% - 170px); /* 100% - width of left bar plus margin */ } 

With a small amount of vanilla JS to toggle it the class:

var wrapper = document.querySelector(".global-wrapper"); document.getElementById("expand").onclick = function() {         wrapper.classList.toggle("expanded"); } 
like image 96
Zach Saucier Avatar answered Nov 19 '22 23:11

Zach Saucier