简体   繁体   中英

Header position: fixed

I would like to know if by any chance I can have a fixed header still at the screen when I scroll down and how can I do it?

I tried to add to the CSS position: fixed; in the .header.dark class but it's breaking the template.

Thanks for your help.

Should work OK. Try this:

<div class="header">This is the header</div>

CSS

.header {
    position:fixed;
    width:100%;
    top:0;
    left:0;
    background:blue;
    z-index:999;
}

Try separating the two classes in your css code with a space. From this:

.header.dark {
//fixed position
}

To this:

.header .dark {
// fixed position
}

I don't know what your code looks like but if you're trying to do something like this

<h1 class="three four">Double Class</h1>

then your css would look like this

.three.four { color: red; }

But if you're trying to do something like this

<div class="header">
<div class="dark">Stay at top</div>
</div>

then your css would look like this

.header .dark { position:fixed; }

Here's a good reference: http://css-tricks.com/multiple-class-id-selectors/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM