I have created an HTML paragraph by using the <p>
tag. The dimensions of the paragraph block are :
If I insert a long continuous line of characters I want a horizontal scrollbar to be displayed. I have tried to set the CSS overflow property but my line of characters is broken and the remaining characters are displayed on a new line.
How can I show an horizontal scrollbar instead of breaking long lines of characters?
If I am seeing your needs correctly, I believe you need to alter the CSS white-space
property:
In my Fiddle above, here is my 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>
Here is my CSS:
p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow: auto;
}
Setting white-space
to nowrap
does away with text wrapping. Setting overflow
to auto
produces a scroll bar when the contents of a block-level elements exceeds its dimensions.
You could alternatively alter the word-wrap
property, but this property is a CSS3 property, while white-space
is CSS1 property. The latter is more widely supported.