2011-04-11 83 views
1

由於我不知道正確的術語,所以我很難說出這個問題。我正在嘗試創建一個網站,以便在滾動主要內容時不會滾動頁面。我希望主要內容在頁面中間的某個地方結束,以免覆蓋我的「固定」背景圖像。但我不想要一個iframe。換句話說,它看起來有點像iframe,但它應該由主滾動條控制。頁面內容不能滾動頁面(無iframe)

無論如何,我希望這是有道理的。我會很感激你的建議。

回答

0

可以使用兩個<div> s,它將覆蓋頂部和底部,以便您的文本可以放在它們的下面。

+----------------+ 
|+--------------+| 
|| top  || 
|+--------------+| 
| your text  | 
|  text  | 
|+--------------+| 
|| bottom  || 
|+--------------+| 
+----------------+ 

z-index,所述topbottom將超過主層,並且它們將被定位fixed到左上角和左下角。

位置:http://jsfiddle.net/FE2Wg/3/

+0

謝謝你的所有意見! iuliux,是的,這是我想要做的。預計我只想使用主滾動條來滾動我的內容條目。我是新手,在你離開我的鏈接之前,我不知道JS的小提琴!謝謝。無論如何,我已經在這裏添加了我的代碼:http://jsfiddle.net/callcan/9Nu5c/ – Candice 2011-04-13 18:54:34

+0

但它使用主滾動條進行滾動。你能不能嘗試清理一下你的代碼,所以你只留下了相關的部分,因爲很難合作,很雜亂。抱歉。 – 2011-04-14 18:55:40

+0

對不起。我清理了我的代碼。我會盡力與你在上一篇文章中提出的建議一起工作。這是我需要的,但我想我只是在執行時遇到問題。我對此仍然很陌生。 – Candice 2011-04-14 22:36:26

0

您是否已經使用background-attachment: fixed;

overflow-y: scroll;與div?

+0

這將創建一個新的滾動條,以他的DIV,我相信 – 2011-04-11 23:13:04

+0

的確。固定背景是要走的路。 – Calum 2011-04-11 23:15:43

0

你想在你的HTML塊中顯示滾動條,對吧?嘗試使用CSS溢出屬性。

參考:www.w3schools.com/css/pr_pos_overflow.asp

在您的網頁代碼試試這個:

<style type="text/css"> 
<!-- 
div.scroll { 
height: 200px; 
width: 300px; 
overflow: auto; 
border: 1px solid #666; 
background-color: #ccc; 
padding: 8px; 
} 
--> 
</style> 
<div class="scroll"> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
    <p>This is a scrolling are created with the CSS property overflow.</p> 
</div> 

這是你正在試圖做的?

+0

不,我試圖讓只有內容條目使用主滾動條滾動。我不想在頁面中間有一個滾動條。這裏是我正在使用的代碼的鏈接。 http://jsfiddle.net/callcan/9Nu5c/ – Candice 2011-04-13 22:33:40