2013-02-26 100 views
8

我有一個主頁面上有一些內容。然後我彈出一個比屏幕更長的模式,所以我必須滾動才能看到它。我需要做什麼,我的CSS只做滾動div而不是整個頁面?滾動覆蓋div沒有滾動整個頁面

下面是模式

#overlay { 
    visibility: hidden; 
    position: absolute; 
    left: 45%; 
    width:auto; 
    border:1px solid #A17E13; 
    height:auto; 
    text-align:left; 
    z-index: 1000; 
} 
#overlay div { 
    background-color:#FCFBEC; 
} 

這裏的CSS是HTML:

<html><body> 
    <div>main page</div> 
    <div id="overlay"> 
    <div> 
     <div> 
      <asp:Label ID="test">Text for modal here</asp:Label> 
     </div> 
    </div> 
    </div> 
</body></html> 
+1

哪裏是你的代碼的其餘部分。隨着你展示的是不可能看到你的結構。 – 2013-02-26 20:10:58

+0

就是這樣。該結構是簡單的主要股利,然後單獨的股利爲模態。 – user541597 2013-02-26 20:22:54

+0

你可以限制你的模式只有屏幕的大小,沒有更大的? – 2013-02-26 20:29:44

回答

4

擁有整個頁面不被滾動除了模態的div?如果是的話,你可以試試位置:固定;在頁面上。模態必須位於外部:絕對;

<!DOCTYPE html> 
<html> 
<head> 
<style type="text/css"> 
#overlay { 
    /*visibility: hidden;*/ 
    position: fixed; 
    left: 45%; 
    width:auto; 
    border:1px solid #A17E13; 
    height:900px; 
    text-align:left; 
    background-color:orange; 
} 
.scroller { 
    height:3000px; 
    width:400px; 
    background-color:green; 
} 
</style> 
</head> 
<body> 
    <div id="overlay"> 
     this is not moving 
    </div> 

    <div> 
     <div class="scroller"> 
      <asp:Label ID="test">This is moving if big enough</asp:Label> 
     </div> 
    </div> 
</body> 
</html> 

Fiddle here