[英]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;
我试图添加到CSS
position: fixed;
in the .header.dark
class but it's breaking the template. 在
.header.dark
类中,但它破坏了模板。
Thanks for your help. 谢谢你的帮助。
Should work OK. 应该工作正常。 Try this:
尝试这个:
<div class="header">This is the header</div>
CSS 的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. 尝试用空格分隔CSS代码中的两个类。 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 然后你的CSS看起来像这样
.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 然后你的CSS看起来像这样
.header .dark { position:fixed; }
Here's a good reference: http://css-tricks.com/multiple-class-id-selectors/ 这是一个很好的参考: http : //css-tricks.com/multiple-class-id-selectors/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.