HTML абзац + горизонтальная полоса прокрутки - PullRequest
0 голосов
/ 27 марта 2012

Я создал абзац HTML с помощью тега <p>. Размеры блока абзаца:

  • Размер X: 300 пикселей.
  • Y-размер: 400px.

Если я вставлю длинную непрерывную строку символов, я хочу, чтобы отображалась горизонтальная полоса прокрутки. Я попытался установить свойство переполнения CSS, но моя строка символов повреждена, а остальные символы отображаются в новой строке.

Как я могу показать горизонтальную полосу прокрутки вместо того, чтобы разбивать длинные строки символов?

Ответы [ 3 ]

5 голосов
/ 27 марта 2012

Если я правильно вижу ваши потребности, я считаю, что вам нужно изменить свойство 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>​

Вот мой CSS:

p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow: auto;
}​

Установка white-space в nowrap устраняет перенос текста.Установка overflow в auto создает полосу прокрутки, когда содержимое элементов уровня блока превышает его размеры.

Вы можете альтернативно изменить свойство word-wrap, но это свойство является свойством CSS3, в то время какwhite-space является свойством CSS1.Последнее более широко поддерживается.

2 голосов
/ 27 марта 2012
#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).

1003 *

Вы можете просмотреть jsfiddle здесь

0 голосов
/ 18 декабря 2012

вставьте это в свой CSS:

p {
   max-width: 300px;
   max-height: 400px;
   white-space: nowrap;
   overflow-x: scroll;
   }  ​
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...