在2个固定div(顶部和底部)之间滚动文本内容

时间:2016-01-20 11:49:02

标签: html css

https://jsfiddle.net/4n496n23/1/

顶部块包含图像,因此我们并不知道它的高度。

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>

3 个答案:

答案 0 :(得分:1)

你可以使用flex:

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>

答案 1 :(得分: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;
}

答案 2 :(得分:0)

这是一个固定的小提琴:https://jsfiddle.net/4n496n23/9/

大多数修复都在这个div上:

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

还更改了其他div的position值,并创建了一个视口大小的固定包装器。祝你好运。

相关问题