【问题标题】:How to make an image static when scrolling滚动时如何使图像静止
【发布时间】:2013-08-25 03:53:47
【问题描述】:

所以我在页面顶部有一个边框,我希望它在我向下滚动时保持在同一个位置。我尝试将position: fixed 放在许多不同的位置,但仍然无法正常工作。另外,如果可能的话,我希望其他内容在此图像后面滚动。这是我的代码:

    <div style='
      background-image: url(http://i111.photobucket.com/albums/n144/baby_painting/bowlace2.gif);
      background-repeat: repeat-x;'>
         <img src="http://i111.photobucket.com/albums/n144/baby_painting/bowlace2.gif">
    </div>

这是页面 nikkidarlinggg.tumblr.com 对不起,如果我没有正确输入这个,我以前从未使用过这个网站。

【问题讨论】:

    标签: html background border fixed


    【解决方案1】:

    这将解决您的问题:

       <div  class='fixed' ></div>
       <div class='content'>Your content here </div>
    

    和固定类:

    .fixed{
     position:fixed;
     top:0;
     z-index: 1;
     width:100%;
     height:100%;
     background-image:url(http://i111.photobucket.com/albums/n144/baby_painting/bowlace2.gif);background-     
     repeat: repeat-x; 
    }
    .content{margin-top:57px;}
    

    在你的 html 中的 css 中使用 css:

       <div style="position:fixed; top:0; z-index: 1; width:100%;height:100%;background-image:url(http://i111.photobucket.com/albums/n144/baby_painting/bowlace2.gif);background-repeat: repeat-x;" >
      </div>
      <div style='margin-top:57px;'>Your content here </div>
    

    在这里演示:http://jsfiddle.net/Nsuj7/

    【讨论】:

    • 这个小提琴不起作用。可以更新一下吗?
    【解决方案2】:

    将这些样式添加到 div:

    position: fixed;
    width: 100%;
    z-index: 10;
    

    【讨论】:

    • 谢谢!另外,如何在边框下方创建一个空间,以便在第一次访问页面时不接触图像?我知道它会在我开始滚动后重叠。我可以使用类似的东西:padding-bottom:10px; ?
    • 要在图像上方添加一些间距,请将以下样式添加到 id="cage" 的 div 中:padding-top: 55px
    • 我对代码知之甚少,我应该把它放在哪里?带有我的文本的侧边栏也会向下移动吗?因为我也希望它更低。
    • 您可以将
      替换为
    • 我想通了。非常感谢
    【解决方案3】:

    你试过了吗:position:absolute

    【讨论】:

      【解决方案4】:
      <div style="background-image: url(http://i111.photobucket.com/albums/n144/baby_painting/bowlace2.gif);background-repeat: repeat-x;position:fixed;width:100%;z-index:2;height:57px"></div>
      

      试试这个,使用 z-index 2 或任何上述值。

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签