如何获得一个div,如果它超过一定的高度,将换行符视为重要的滚动? [英] How can I get a div that treats line breaks as significant to scroll if it exceeds a certain height?

查看:180
本文介绍了如何获得一个div,如果它超过一定的高度,将换行符视为重要的滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下代码:

<div style="height: 100px; max-height: 100px; white-space: pre-wrap;">
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
</div>

当我在浏览器中加载该页面时,它垂直显示小写字母,

When I load that page in a browser, it displays, vertically, the lowercase alphabet, and does not scroll.

我应该做什么不同,以使DIV保留源断行符,但具有我指定的高度,如果内容高度超过最大值,滚动条已设置?

What should I do differently so that the DIV retains source line breaks, but has exactly the height I specify, with a scrollbar if the content height exceeds the maximum I have set?

感谢,

推荐答案

$ c> overflow:auto 或 overflow:scroll 到您的div。

Just add overflow: auto or overflow: scroll to your div.

a href =http://jsfiddle.net/g4qfL/1/ =nofollow>检查这个小提琴这是你想要的吗?

Check this fiddle. Is this what you want?

这篇关于如何获得一个div,如果它超过一定的高度,将换行符视为重要的滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆