How to make LI elements wrap in UL? [duplicate] - html

I have a situation where there can be long words like 'hellowordsometext' or integer like '1234567891122' without any space in between. check this js please. http://jsfiddle.net/rzq5e/6/
how is it possible to break it in to next line after it reach the div width. what happens now is, it spans out out along with th div
<div>Solutionforentprise</div>

What you need is word-wrap: break-word;, this property will force the non spaced string to break inside the div
Demo
div {
width: 20px;
word-wrap: break-word;
}

I have found this solution my self.
word-break: break-all;
but it doesn't work for Opera.
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-break

The other answers have some problems with old browsers, like before Chrome 32.
Its better to use this code:
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
You can also add a hyphen where the word breaks (if supported):
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
Source
.c1 {
width: 200px;
border: 1px solid;
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
<div class="c1">
For more information, please visit: http://csstricks.com/thisisanonexistentandreallylongurltoaddtoanytextinfactwhyareyoustillreadingit.
</div>

give an id or class to your div
then
#divid
{
width: 30px;
word-wrap: break-word;
}
Word-wrap is supported in IE 5.5+, Firefox 3.5+, and WebKit browsers such as Chrome and Safari, Opera 10.5+.

Like this
DEMO
CSS
div {
width: 20px;
word-wrap:break-word;
}

Fix the size of the DIV and apply 'overflow: hidden'
so it will not effect the grid size an all na.
div{width: 40px;
overflow: hidden;}
do you need to view entire text?

Related

Flexwrap not working for text inside a container [duplicate]

I have a situation where there can be long words like 'hellowordsometext' or integer like '1234567891122' without any space in between. check this js please. http://jsfiddle.net/rzq5e/6/
how is it possible to break it in to next line after it reach the div width. what happens now is, it spans out out along with th div
<div>Solutionforentprise</div>
What you need is word-wrap: break-word;, this property will force the non spaced string to break inside the div
Demo
div {
width: 20px;
word-wrap: break-word;
}
I have found this solution my self.
word-break: break-all;
but it doesn't work for Opera.
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-break
The other answers have some problems with old browsers, like before Chrome 32.
Its better to use this code:
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
You can also add a hyphen where the word breaks (if supported):
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
Source
.c1 {
width: 200px;
border: 1px solid;
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
<div class="c1">
For more information, please visit: http://csstricks.com/thisisanonexistentandreallylongurltoaddtoanytextinfactwhyareyoustillreadingit.
</div>
give an id or class to your div
then
#divid
{
width: 30px;
word-wrap: break-word;
}
Word-wrap is supported in IE 5.5+, Firefox 3.5+, and WebKit browsers such as Chrome and Safari, Opera 10.5+.
Like this
DEMO
CSS
div {
width: 20px;
word-wrap:break-word;
}
Fix the size of the DIV and apply 'overflow: hidden'
so it will not effect the grid size an all na.
div{width: 40px;
overflow: hidden;}
do you need to view entire text?

How to make html elements scale correctly, when dealing with long text [duplicate]

I have a situation where there can be long words like 'hellowordsometext' or integer like '1234567891122' without any space in between. check this js please. http://jsfiddle.net/rzq5e/6/
how is it possible to break it in to next line after it reach the div width. what happens now is, it spans out out along with th div
<div>Solutionforentprise</div>
What you need is word-wrap: break-word;, this property will force the non spaced string to break inside the div
Demo
div {
width: 20px;
word-wrap: break-word;
}
I have found this solution my self.
word-break: break-all;
but it doesn't work for Opera.
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-break
The other answers have some problems with old browsers, like before Chrome 32.
Its better to use this code:
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
You can also add a hyphen where the word breaks (if supported):
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
Source
.c1 {
width: 200px;
border: 1px solid;
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-word;
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
<div class="c1">
For more information, please visit: http://csstricks.com/thisisanonexistentandreallylongurltoaddtoanytextinfactwhyareyoustillreadingit.
</div>
give an id or class to your div
then
#divid
{
width: 30px;
word-wrap: break-word;
}
Word-wrap is supported in IE 5.5+, Firefox 3.5+, and WebKit browsers such as Chrome and Safari, Opera 10.5+.
Like this
DEMO
CSS
div {
width: 20px;
word-wrap:break-word;
}
Fix the size of the DIV and apply 'overflow: hidden'
so it will not effect the grid size an all na.
div{width: 40px;
overflow: hidden;}
do you need to view entire text?

Truncate a long text on mobile phones

I have a question!
My div can have a long text. This div doesn't have fixed height, and I have trouble on mobile phones.
For instance, my device has width 320px, but the inner div has width 454px.
It happens to long words.
You can see my issue on codepen.
Can I fix it only with CSS?
I would be grateful if you could help me to fix this!
use this css code:
p{width:100px;
height:auto;
border:2px solid #000;
overflow-wrap: break-word;}
<p> this is a biggggggggggggggggggg word</p>
I've fixed my issue with this css code:
.breaking {
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}
CBroe, thanks for your help.

How to break a long sentence in correct places in IE

I have to display really long sentences in a paragraph in a div. Couple of things I have to take care for this situation. 1. The lines should not go out of bound 2. The wrapping/breaking of the sentence should happen at the appropriate places, such as spaces between words. The following CSS works really well in Chrome. The code is from https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/ with a minor modification.
.handle-long-sentence{
white-space: normal;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
In IE11, the paragraph is displayed as flush with the word breaking randomly at various places.
Thanks
Finally I have found the CSS which worked in all three major browsers
.handle-long-sentence{
white-space:normal;
white-space: -moz-pre-wrap; /* Mozilla */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
-o-hyphens: auto;
hyphens: auto;
}
This puts an hyphen in IE whenever a word is broken. In Chrome and Firefox, no word is broken and the space between words is used for word wrapping.

How to wrap long text inside a div without scroll

<div style="width:200px; margin:0 auto;"> 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........
</div>
The above code is showing a long scrollbar. I want to keep it inside the div's declared width (width: 200px;) without scrolling.
I have tried float, display, position, overflow, but nothing works here.
Alternative you can use overflow-wrap: break-word;. Also avoid inline styles.
css
div{
width: 200px;
margin: 0 auto;
overflow-wrap: break-word;
word-wrap: break-word; /* Firefox support */
}
Fiddle
Try this:-
word-wrap: break-word;
DEMO: http://jsfiddle.net/dwebexperts/thyD9/
<div style="width:200px; margin:0 auto; word-wrap:break-word;"> 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........
</div>
JSFiddle: http://jsfiddle.net/Emr84/
Try this:
div {
width:200px;
margin:0 auto;
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* IE */
}
Note: Avoid inline styling.
Demo
Try with these CSS rules
white-space: nowrap; //keep the text on one line
overflow: hidden; //prevent the text from being shown outside the border
text-overflow: ellipsis; //cut off text with an elipsis
Use text-overflow: ellipsis;.
Full explanation: http://quirksmode.org/css/user-interface/textoverflow.html
for me following worked, my div was inside a scrollable parent div, just add to your child or content div
div{
white-space: normal;
}
OR
div{
white-space: pre-wrap;
}