简体   繁体   English

CSS标头固定位置

[英]CSS Header Fixed Position

I have a site that horizontally scrolls across five page widths. 我有一个横向滚动五页宽度的网站。 I want the header to stay fixed in the same position while the pages scroll horizontally. 我希望页面在页面水平滚动时保持固定在相同位置。 In Safari, the header stays with the css rule, "position:fixed". 在Safari中,标题符合css规则“position:fixed”。 In Firefox, Chrome and IE, however, the header scrolls with the pages. 但是,在Firefox,Chrome和IE中,标题随页面滚动。 Is there an easier way than pulling the header out of the wrapper for each page? 有没有比从每个页面的包装器中拉出标题更简单的方法? The code is complicated so I want to avoid pulling it outside. 代码很复杂,所以我想避免将其拖到外面。

<div id="page1">
    <div class="header"></div>
</div>
<div id="page2">
    <div class="header"></div>
</div>
<div id="page3">
    <div class="header"></div>
</div>
.header {
    width:100%;
    height:110px;
    background-color: rgba(43, 77, 105, .6);
    z-index: 10;
    position: fixed;
   top:0;
}

You can try adding left:0 property for .header class to fix the issue 您可以尝试为.header类添加left:0属性来解决问题

Happy Coding :) 快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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