2016-01-20 89 views
0

https://jsfiddle.net/4n496n23/1/請滾動2周固定的div(頂部和底部)

頂塊包含圖像之間的文本內容,所以我們真的不知道它的高度。

HTML

<div id="top-block"> 

</div> 
<div id="text-block"> 
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. 
</div> 
<div id="bottom-block"> 

</div> 
+0

你有多提供最大高度頂塊? – 2016-01-20 11:55:15

+0

頂部擋塊高度可以達到60% –

+0

不是,這是不同的問題。如果你將包裝塊(命名部分)高度更改爲100%,它會消除 –

回答

0

這裏有一個固定的小提琴:https://jsfiddle.net/4n496n23/9/

大部分的修復都在這個div:

#text-block { 
    display:block; 
    height:calc(100% - 4.5em); 
    font-size: 2em; 
    overflow-Y: scroll; 
} 

還更改了其他div的position值,並創建了視口大小的固定包裝。祝你好運。

+0

哇! Tnx很多! –

+0

沒問題。考慮提出答案,並在這個下面引用'flex'的答案。 –

0

請檢查你想達到什麼樣的撥弄這隻與否 jsfiddle

<div id="text-block"> 
<span> Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</span> 
</div> 

#text-block { 
    font-size: 2em; 
    overflow-y: scroll; 
    height:9em; 
    margin-top:3em; 
} 
1

您可以使用柔性:

html, 
 
body { 
 
    height: 100%; 
 
    margin: 0; 
 
} 
 
body { 
 
    display: flex; 
 
    flex-flow: column; 
 
} 
 
#top-block { 
 
    background-color: #569688 
 
} 
 
#text-block { 
 
    font-size: 2em; 
 
    overflow: auto; 
 
    flex: 1; 
 
} 
 
#bottom-block { 
 
    background-color: #b9e111 
 
}
<div id="top-block"> 
 
    The Extremes 
 
    <br/>of Good 
 
</div> 
 
<div id="text-block"> 
 
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up 
 
    one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum 
 
    et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 
 
    1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English 
 
    versions from the 1914 translation by H. Rackham. 
 
</div> 
 
<div id="bottom-block"> 
 
    Finibus Bonorum 
 
</div>