2014-03-28 44 views
5

如何讓背景圖像保持靜止並僅滾動文本?在靜態圖像上滾動文本css

#wrapper{ 
    height: 100%; 
    width: 100%; 
    background-image: url('background.jpg'); 
    background-size: 100%; 
    background-position: fixed; 
} 

這是我對背景的造型,但它仍然滾動,留下白色空間,直到文字到達底部。我一直在爲此搜索一個小時。這是我第一次嘗試使用CSS,所以請不要對我苛刻。

回答

2
<style> 
     #test { 
      background-image: url(./images/grad.gif); 
      background-attachment: fixed; 

      /* 
       the three following items below do the following: 
       a) fix the width and height of the containing div 
        to be smaller than the width and height of the content. 
       b) we set the overflow style so that when the content is 
        bigger than the containing element scroll bars appear 
        to allow users to scroll the element contents. 
      */ 
      height:200px; 
      width:300px; 
      overflow:scroll; }  
    </style> 

    <div id="test"> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 
     <div style="border:3px solid white; margin:20px; width:80%"> 
     test test test test test test test test test <br/> 
     test test test test test test test test test <br/> 
     test test test test test test test test test <br/> 
     test test test test test test test test test <br/> 
     </div> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 
     test test test test test test test test test test test <br/> 


    </div> 

更多信息:http://www.codertools.com/css_help_guide/css_background-attachment.aspx

+0

溢出:滾動; 加入以上已修復它在我的情況。 非常感謝! – virmantas

0

我相信background-attachment:fixed應該可以解決這個問題。當然,這不是真正的信念問題,但MDN似乎這樣說。

-1

使用此CSS代替,以防止平鋪圖像,並使在它的文本滾動:

background: url('your_background.jpg') no-repeat fixed;