HTML段落+水平滚动条

use*_*666 0 html scrollbar paragraph

我使用<p>标记创建了一个HTML段落.段落块的尺寸为:

  • X尺寸:300px.
  • Y尺寸:400px.

如果我插入一长串连续的字符,我想要显示一个水平滚动条.我试图设置CSS溢出属性,但我的字符行被破坏,其余字符显示在一个新行上.

如何显示水平滚动条而不是打破长行字符?

dan*_*007 5

如果我正确看到您的需求,我相信您需要更改CSS white-space属性:

http://jsfiddle.net/kSUS8/

在上面的小提琴中,这是我的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>?
Run Code Online (Sandbox Code Playgroud)

这是我的CSS:

p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow: auto;
}?
Run Code Online (Sandbox Code Playgroud)

设置white-spacenowrap消除文本换行.设置overflowauto在块级元素的内容超出其尺寸时生成滚动条.

您也可以更改word-wrap属性,但此属性是CSS3属性,而white-spaceCSS1属性.后者得到更广泛的支持.