Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - "position: fixed" acting like "absolute" in Firefox

I've been building a website in Safari, and I've just tested it in Firefox and my fixed navigation elements are behaving as if they're position is absolute.

#navigation {
    display: block;
    width: 100%;
    height: 50px;
    position: fixed;
    left: 0px;
    bottom: 0px;
    text-align: center;
    z-index: 99000;
}

This is the CSS I have for the primary navigation wrapper (it's a bottom nav.). In Webkit, it works perfectly: that is, it sticks to the bottom of the window regardless. In firefox, it positions itself at the end of the tags, so, for example, on a long page, I'd have to scroll down just to see it. It is acting as if it's absolute.

I also have a sidebar navigation.

.slidebar {
    display: block;
    position: fixed;
    left: -1px;
    top: -1px;
    width: 1px;
    height: 100%;
    overflow: hidden;
    -webkit-transition: all 300ms ease;
    -moz-transition: all 300ms ease;
    -o-transition: all 300ms ease;
    -ms-transition: all 300ms ease;
    transition: all 300ms ease;
    z-index: 99998;
}

This sidebar is also acting as if it's absolute - that is, it is positioning itself off the screen properly, but it's elongating <body> and thus the horizontal scrollbar appears. The height: 100%; is also responding to the <body> height and not the window height, so, for example, my <header> has a top margin of 20px, and the slidebar observes that margin too (the body has 0 margin). Likewise, instead of the height: 100%; ending at the bottom of the window, it ends at the bottom of the <body>, factoring in the footer's bottom margin.

I cannot understand for the life of me why this is happening. Element inspection shows all the properties are loading fine, and in Chrome and Safari it works. It worked initially, and it worked the last time I even edited either navigation, but it has since stopped working since I built other, irrelevant, parts of the site.

http://www.upprise.com/demo.php - click the Envelope icon to see the sidebar

like image 990
user2250471 Avatar asked Jan 29 '14 19:01

user2250471


People also ask

How do I fix fixed position in CSS?

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.

Is position fixed absolute?

Fixed positioning is really just a specialized form of absolute positioning; elements with fixed positioning are fixed relative to the viewport/browser window rather than the containing element; even if the page is scrolled, they stay in exactly the same position inside the browser window.

Which of the CSS position property is the same as the absolute position?

Fixed positioning is similar to absolute positioning, with the exception that the element's containing block is the initial containing block established by the viewport, unless any ancestor has transform , perspective , or filter property set to something other than none (see CSS Transforms Spec), which then causes ...

What can I use instead of position absolute?

Fixed. The fixed value is similar to absolute as it can help you position an element anywhere relative to the document, however this value is unaffected by scrolling.


3 Answers

I had the exact same problem, turns out the following CSS property of a parent element was causing the problem.

transform: translate3d(0px, 0px, 0px);
like image 153
Pankaj Avatar answered Oct 02 '22 21:10

Pankaj


Through the process of elimination I was able to determine that having the following in my body was causing all the problems with fixed divs in Firefox:

-o-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;

I had originally added this code to prevent flickering in certain CSS transitions throughout the site, but I guess I'll have to add it to each individual class now.

like image 36
user2250471 Avatar answered Oct 02 '22 22:10

user2250471


It appears that some browsers will will apply fixed positioning relative to the window, while Firefox is applying it relative to the <body />. You need to make your body 100% tall:

body {
    height: 100%;
}

But the margin from your .header is collapsing outside of the body element. Change this:

margin: 25px auto;

to this:

margin: 0 auto; /* updated - thanks JoshC */
padding: 25px auto;
like image 36
Ryan Wheale Avatar answered Oct 02 '22 21:10

Ryan Wheale