2015-10-02 38 views
5

我之前有一個問題,我想expand a div from the center of the body。它工作正常,直到我遇到這種情況,其中正文的內容足夠長,滾動條現在顯示。從視口中心展開div

關於此jsFiddle的注意事項是,當我滾動到底部或只是中途點擊頁面上的任何位置時,展開的div將顯示在頁面的最頂部。

我知道這下面的CSS代碼有什麼用它做:

.growme { 
    background-color: #990000; 
    height: 0; 
    width: 0; 
    position: absolute; 
    filter: alpha(opacity=0); 
    opacity: 0; 
    top:0; 
    left:0; 
    bottom:0; 
    right:0; 
    margin:auto; 
} 

我怎麼能做出格在視口右側正好擴大無論在哪裏,我滾動?

回答

6

只要改變你的固定位置(使用視口):

.growme { 
    background-color: #990000; 
    height: 0; 
    width: 0; 
    position: fixed; 
    filter: alpha(opacity=0); 
    opacity: 0; 
    top:0; 
    left:0; 
    bottom:0; 
    right:0; 
    margin:auto; 
} 

這裏是一個演示:http://jsfiddle.net/w5w8orvp/

+0

沒想到那個!哈!非常感謝@Goowik – basagabi

1

你可以試試這個:

.growme { 
    background-color: #990000; 
    height: 0; 
    width: 0; 
    position: absolute; 
    filter: alpha(opacity=0); 
    opacity: 0; 
    top:0; 
    left:0; 
    bottom:0; 
    right:0; 

    overflow:scroll; 
} 

DEMO FIDDLE

.growme { 
    background-color: #990000; 
    height: 0; 
    width: 0; 
    position: absolute; 
    filter: alpha(opacity=0); 
    opacity: 0; 
    top:0; 
    left:0; 
    bottom:0; 
    right:0; 
    margin:auto; 

} 
p 
{ 
    text-align:center; 
} 

Here My Demo

DEMO UPDATED

+1

似乎從這裏:) – nowhere

+0

有同樣的問題這個答案正確或錯誤的@nowhere –

+1

該div仍然顯示不居中(如果我明白這個問題是這個問題) – nowhere