Daniel Daniel - 1 month ago 5
CSS Question

CSS: how to create a fixed top header with a fixed width

I have following fixed top header using this class:


.sticky {
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 100;
border-top: 0;


}

now, I would like to have a fixed width (840px) not 100% and centered as shown in this example:


https://jsfiddle.net/jobgaraux/yv3hykLo/2/

Answer
.sticky {
position: fixed;
width: 840px;
margin-left: -420px
left: 50%;
top: 0;
z-index: 100;
border-top: 0;
}

This is the solution.