我使用<p>
标记创建了一个HTML段落。段落块的尺寸为:
如果我插入一长串连续的字符,我想要显示一个水平滚动条。我试图设置CSS溢出属性,但我的字符行被破坏,其余字符显示在一个新行上。
如何显示水平滚动条而不是打破长行字符?
答案 0 :(得分:5)
如果我正确看到您的需求,我相信您需要更改CSS white-space
属性:
在上面的小提琴中,这是我的HTML。
<p>
But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
</p>
这是我的CSS:
p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow: auto;
}
将white-space
设置为nowrap
会取消文本换行功能。当块级元素的内容超出其维度时,将overflow
设置为auto
会生成滚动条。
您也可以更改word-wrap
属性,但此属性是CSS3属性,而white-space
是CSS1属性。后者得到更广泛的支持。
答案 1 :(得分:2)
#box {
width:300px;
height:400px;
word-wrap:normal;
overflow:scroll;
}
<p id="box">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
您可以查看jsfiddle here
答案 2 :(得分:0)
把它放在你的CSS中:
p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow-x: scroll;
}
答案 3 :(得分:0)
尝试在 CSS 中使用 filter_input_array()
。这应该使您的段落自动具有滚动条。