CSS粘头 [英] CSS Sticky header

查看:146
本文介绍了CSS粘头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页上添加了一个粘性标题,但粘性标题似乎在页面上其余内容的后面,所以当我向下滚动页面时,图像和文本位于标题顶部,是

以下是我的代码:

  <风格> 
/ *重置主体填充和边距* /
body
{
margin:0;
padding:0;
}

/ *制作标题粘贴* /
#header_container
{
background:#827878;
border:1px solid#666;
height:60px;
剩下:0;
位置:固定;
宽度:100%;
top:0;
}

#标题
{
line-height:60px;
保证金:10汽车;
width:940px;
text-align:left;
font-size:26px;
颜色:#f5f5f5;
line-height:28px;
margin-bottom:14px;
font-family:'Source Sans Pro',sans-serif;
}

/ * CSS为页面内容。我给了80px的顶部和底部
填充以确保页眉和页脚
不与内容重叠。 * /
#container
{
margin:0 auto;
溢出:auto;
填充:80px 0;
width:940px;
}

#content
{
}

/ *制作页脚粘性* /
#footer_container
{
background:#eee;
border:1px solid#666;
bottom:0;
height:60px;
剩下:0;
位置:固定;
宽度:100%;
}

#footer
{
line-height:60px;
margin:0 auto;
width:940px;
text-align:center;
}
< / style>


<! - BEGIN:粘滞标题 - >
< div id =header_container>
< div id =header>
标题内容
< / div>
< / div>
<! - END:粘滞标题 - >


解决方案

添加此代码..添加z-index:1000在#header_container& amp; amp; z-index:1001在#header风格中

  #header_container 
{
position:fixed;
top:0px;
left:0px;
z-index:1000;
}

#header {
z-index:1001;
}


I have added a sticky header to my homepage, however the sticky header seems to be behind the rest of the content on the page, so when i scroll down the page, images and text are on top of the header, is there a way to stop this?

Here is my code:

<style>
/* Reset body padding and margins */
body
{
    margin: 0;
    padding: 0;
}

/* Make Header Sticky */
#header_container
{
    background: #827878;
    border: 1px solid #666;
    height: 60px;
    left: 0;
    position: fixed;
    width: 100%;
    top: 0;
}

#header
{
    line-height: 60px;
    margin: 10 auto;
    width: 940px;
    text-align: left;
    font-size: 26px;
    color: #f5f5f5;
    line-height: 28px;
    margin-bottom: 14px;
    font-family: 'Source Sans Pro',sans-serif;
}

/* CSS for the content of page. I am giving top and bottom 
   padding of 80px to make sure the header and footer 
   do not overlap the content. */
#container
{
    margin: 0 auto;
    overflow: auto;
    padding: 80px 0;
    width: 940px;
}

#content
{
}

/* Make Footer Sticky */
#footer_container
{
    background: #eee;
    border: 1px solid #666;
    bottom: 0;
    height: 60px;
    left: 0;
    position: fixed;
    width: 100%;
}

#footer
{
    line-height: 60px;
    margin: 0 auto;
    width: 940px;
    text-align: center;
}
</style>


<!-- BEGIN: Sticky Header -->
<div id="header_container">
    <div id="header">
        Header Content
    </div>
</div>
<!-- END: Sticky Header -->

解决方案

Add this code.. Add z-index:1000 in both #header_container & z-index:1001 in #header styles

 #header_container 
      { 
        position:fixed;
        top:0px;
        left:0px;
        z-index:1000;
       }

 #header{
      z-index:1001;
      }

这篇关于CSS粘头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆