2011-06-24 72 views
3

只需檢查是否有方法在CSS中執行此操作,然後再啓動Javascript即可!CSS,具有動態內容的固定位置Div - 如何在其下方放置另一個Div?

在該示例中,#fixed div被動態填充內容 - 所以我們永遠不知道該div內容會有多大。

#absolute div的開頭必須始終在#fixed div下面呈現。 #absolute div也會動態地填充冗長的內容,所以用戶必須能夠滾動該div中的內容,無論它有多大。

不知道#fixed div的大小,有沒有一種方法只使用CSS,我們可以將#absolute div的開頭保留在#fixed div下面?

XHTML:

<div id="right"> 
    <p>This div is just here to force a scrollbar.</p> 
</div> 

<div id="fixed"> 

    <p>This div gets filled dynamically with content of varying length</p> 

</div> 

<div id="absolute"> 

    <p>This div also gets filled dynamically with content of varying length, 
    and needs to stay underneath the div above.</p> 

    <p>This div will sometimes get so high that it stretches below the bottom of the page, 
    and because it's inside a fixed positioned div the user won't be able to read all of its content.</p> 

</div> 

CSS:

#fixed { 
    position:fixed; 
    border:2px solid green; 
    width:200px; 
    display:block; 
    background-color:white; 
} 

#absolute { 
    position:absolute; 
    border:2px solid red; 
    width:200px; 
    margin-top:90px; 
    z-index:-1; 
} 

#right { 
    position:absolute; 
    right:0px; 
    width:200px; 
    height:4000px; 
    border:2px solid blue; 
} 

回答

1

如果不知道#FIXED div的大小,有沒有隻使用CSS 的方式,我們可以繼續在下面的#absolute div的開始#fixed div?

沒有CSS不能幫你這裏。

absolute/fixed元件是...

從正常流動完全 ([和具有]對後面的兄弟姐妹沒有影響)除去。

和:

絕對 定位元素的內容不會四處流動 任何其他框

http://www.w3.org/TR/CSS21/visuren.html#absolute-positioning

+0

我認爲不是!感謝您的回覆:) – FrediDoo

+0

沒問題。你需要JavaScript的幫助嗎? – thirtydot

+0

我很好,再次感謝! – FrediDoo