Reputation: 1697
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?
Upvotes: 0
Views: 9319
Reputation: 1
Try using overflow: scroll
in CSS. That should make it so your paragraph automatically has scrollbars.
Upvotes: 0
Reputation: 2909
put this in your CSS:
p {
max-width: 300px;
max-height: 400px;
white-space: nowrap;
overflow-x: scroll;
}
Upvotes: 0
Reputation: 1805
#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).
You can view the jsfiddle here
Upvotes: 2
Reputation: 20895
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.
Upvotes: 7