Jared Jared - 6 days ago 5
CSS Question

CSS position fixed AND margin 0 auto

So I have a background image with the following css:

body{
background-image:url(cover.jpg);
background-repeat:no-repeat;
background-position:center;
background-attachment:fixed;
}


And the background image is 1280 px in width. So I want my navigation bar fixed and centered with the background. However Im running into issues. Here is my code.

#navigation {
margin: 0 auto;
position:fixed;
top: 0;
width: 1280px;
height: 35px;
padding-top: 10px;
background-color: #000000;
}


But the navigation bar will be fixed but not centered. If I remove the fixed, it will center it but then its not fixed.

Any ways to accomplish this?

Answer

you can make the following

#navigation {
    position:fixed;
    left:0;
    right:0;
    margin-left:auto;
    margin-right:auto;
    width: 1280px;
    height: 35px;
    padding-top: 10px;
    background-color: #000000;
}
Comments