2016-01-20 91 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>