2014-02-20 263 views
0

我想知道如果有任何机会,我可以在屏幕上有一个固定的标题,当我向下滚动时,我该怎么做?头位置:固定

我试图添加到.header.dark类中的CSS position: fixed;,但它打破了模板。

感谢您的帮助。

+1

向我们展示你的代码,告诉我们什么你已经尝试过了。设置'position:fixed'通常是在用户滚动浏览相关元素时完成的 – helion3

回答

0

应该可以正常工作。试试这个:

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

CSS

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

尝试在你的CSS代码用空格分隔两班。从这:

.header.dark { 
//fixed position 
} 

要这样:

.header .dark { 
// fixed position 
} 

我不知道你的代码是什么样子,但如果你试图做这样的事情

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

那么你css看起来是这样的

.three.four { color: red; } 

但是,如果你试图做这样的事情

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

那么你的CSS看起来像这样

.header .dark { position:fixed; } 

这里有一个很好的参考:http://css-tricks.com/multiple-class-id-selectors/