I have two inline span. code sample:
<div class="comment_content">
<span class="comment_author"><?= $child_comment['comment_author'] ?></span>
<span class="comment_text"><?= $child_comment['comment_content'] ?></span>
</div>
And scss sample:
.comment_content {
word-wrap: break-word;
}
.comment_author {
display: inline-block;
vertical-align:top;
}
.comment_text {
display: inline-block;
word-wrap: break-word;
width: 100%;
}
If my expected view has to be:
If user enters string without spaces, string won’t break. And breaks design:
How properly break long words ??
Sunil Gehlot
1,5492 gold badges18 silver badges32 bronze badges
asked Apr 5, 2016 at 6:06
Ramūnas PabrėžaRamūnas Pabrėža
5641 gold badge5 silver badges14 bronze badges
1
white-space: nowrap
will prevent word-break
from taking effect. Some templates apply white-space: nowrap
which necessitates overriding this attribute with white-space: normal
.
answered Mar 19, 2019 at 9:08
1
To properly break long-words it requires to combine several CSS properties, I would suggest defining and applying helper class like this:
.break-long-words {
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
}
Properties explained:
- overflow-wrap and word-wrap are aliases for same thing but some browsers support one and not the other so we need them both. They
are offical «correct» way to break words but they don’t have any effect on elements with dynamic width so we need more… - word-break is originally intended for requiring a particular behaviour with CJK (Chinese, Japanese, and Korean) text but works similar to
word-wrap but in WebKit break-all value breaks everything and everywhere. For that reason we must use non-standard and poorly
documented WebKit-only break-word value. - and optionally, if it makes sense for break words to have hypens (ie. for URLs it probably doesn’t) we can use hypens in browsers that
support them (at the moment Firefox, Safari, Edge and IE 10+). Also note that in Firefox hypens don’t work if you have word-brake
property so unless you have fixed-width container you must choose between hypens on FF or legacy support.
Note that I omitted vendor prefixes but if you don’t use something like Autoprefixer than this is full verison:
.break-long-words {
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;
}
answered Apr 11, 2016 at 17:45
Teo DragovicTeo Dragovic
3,41821 silver badges34 bronze badges
4
Use the word-break
style to define where in the word to break to the next line. By default, it uses spaces or hyphens but you can set it to break-all
to allow breaking on any letter:
.comment_text {
display: inline-block;
word-wrap: break-word;
word-break: break-all;
width: 100%;
}
answered Apr 5, 2016 at 6:11
SteveSteve
9,28510 gold badges49 silver badges80 bronze badges
3
I thing it will be helpful. You have to specify width
, particular in your case.
.comment_content{
width:500px;
border:1px solid #ccc;
}
.comment_author{
width: 100px;
float: left;
}
.comment_text{
width: 400px;
word-wrap: break-word;
display:inline-block;
}
<div class="comment_content">
<span class="comment_author">Hello</span>
<span class="comment_text">qeqweqweqweqeeqeqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqweqeqweqweqweqweqweqweqwewqeqweqweqweqweqweqweqweqweqweqeqeqweqweqweqweqweqweqweqweqweqeqewqweqeq</span>
</div>
Here is a working examples to achieve what you want: examples
answered Jun 19, 2017 at 20:47
MirodilMirodil
2,2692 gold badges29 silver badges38 bronze badges
You can use
word-break: break-all;
See fiddle here
fiddle
answered Apr 5, 2016 at 6:13
pradeep1991singhpradeep1991singh
8,0254 gold badges21 silver badges31 bronze badges
1
Please use word-break: break-all;
in .comment_content
class.
answered Apr 5, 2016 at 6:14
Sunil GehlotSunil Gehlot
1,5492 gold badges18 silver badges32 bronze badges
word-break
is not supported for the moment, you should see a warning about that when using the CLI. I’ve at least fixed the documentation about that.
As a workaround, you theoretically could use overflow-wrap: break-word
instead of word-break: break-all
, but it doesn’t work for various unrelated reasons:
- Pango 1.40.13 broke overflow-wrap, it’s fixed in 1.40.14,
- I don’t know how
overflow-wrap: break-word
andwhite-space: nowrap
are supposed to work together (currently,white-space: nowrap
always avoids wrapping), I have to read the spec, - for some unknown reason
overflow-wrap: break-word
doesn’t work in tables.
I’m renaming the issue according to this last point, which is the real bug currently in WeasyPrint. When this bug is fixed, you’ll be able to do what you want in your example.
Answer by Alberto Curtis
When I’m using word-wrap:break-word with Browser Mode: IE9 Compatibility View and Document Mode: IE7 standards its working perfectly fine. However when I change the Document Mode: IE9 standards, its not working.
I’ve also tried using -ms-word-wrap:break-word however its giving me the same result.,it should work, .your_class_name{word-break:break-word;}, i have tested it in ie7 — ie9 and it breaks the word…,Adding -ms-word-break: break-word; worked for me.,
Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers
you need to have
table {
width:100%;
table-layout:fixed;
}
Answer by Bellamy Shepherd
The solution, using the HTML, ZERO-WIDTH-SPACE Unicode Character .,If you are attempting to wrap very long words or hyperlinks within a narrow container, you may experience text overflowing when viewing your results in IE11. This may happen despite using the CSS declaration word-wrap: break-word; in IE 11, but looks fine in other browsers. See below:,There are ways of handling long words and URLs using forced breaks, hyphenation, ellipsis, etc). See the terrific article here on the CSS Tricks website: https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/,What if you do not want a hyphen or ellipsis to appear? Using word-wrap: break-word; overflow-wrap: break-word; word-break: break-all; word-break: break-word; or even the Microsoft CSS Browser Prefix declaration -ms-word-break: break-all;, may not work. It didn’t for me.
CSS
#container {
width: 120px;
background-color:#ccc;
border: 1px solid #aaa;
margin: 50px 50px 0;
}
.break {
word-wrap: break-word;
}
HTML
<div id="container">
<p>Donec sit amet erat porta, rhoncus dolor nec, <span class="break">scelerisqueaghtrafdssf</span> accumsan leo. Phasellus eu ipsum aliquam, <a class="break" href="www.samplewebsite.com/reallylongurl">www.reallylongwebsiteurl.com/reallylongurl</a> rutrum orci a, pulvinar elit. Aenean auctor dignissim tempus.</p>
</div>
Answer by Ila Perez
-max-content it is not supported by IE, according to CanIuse.,So I created a fallback for IE that might help you, by setting .button to display:inline-block:,It’s working, but I don’t want to display the elements inline.,The CSS word-wrap: break-word; works only in display:block; or display:inline-block; elements so you can just use:
I have a small css script that force <a>
tag word-wrap in a div. It worked fine on FF, Chrome but didn’t work on IE9. How can I fix it?
.tab_title a{
word-wrap: break-word;
}
Answer by Kairi Buck
Note: In contrast to word-break, overflow-wrap will only create a break if an entire word cannot be placed on its own line without overflowing.,Report a problem with this content on GitHub,This example compares the results of overflow-wrap, word-break, and hyphens when breaking up a long word.,Browser compatibility
/* Keyword values */
overflow-wrap: normal;
overflow-wrap: break-word;
overflow-wrap: anywhere;
/* Global values */
overflow-wrap: inherit;
overflow-wrap: initial;
overflow-wrap: revert;
overflow-wrap: unset;
Answer by Nash Miller
Also ran into this issue with the ML anomalies table, where fields like job IDs cannot contain spaces, so long values will overflow the cells in Firefox and Edge.,
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
,This property is being used a couple of times for tables to prevent content from overflowing. Works in Chrome:,@cchaos Reopening — fallback styles in #864 doesn’t seem to have been applied to the word-break property on table cells (screenshot on IE11):
Add fallback to just break-all in FF and IE
Answer by Ariya Abbott
It doesn’t work in IE 8 and 9. Do you have any suggestions for IE 8 and 9 for word-wrap: break-word; ?,I’m sorry that last code is working for me in IE8 at the moment…. but not in IE9. I rechecked,for me it does not seem’s to work on Chrome and firefox.,word wrap is not working in this website in firefox
The word-wrap
property accepts two values, one of which is the default:
.selector {
word-wrap: normal; /* the default */
}
.selector-2 {
word-wrap: break-word;
}
If you are attempting to wrap very long words or hyperlinks within a narrow container, you may experience text overflowing when viewing your results in IE11. This may happen despite using the CSS declaration word-wrap: break-word; in IE 11, but looks fine in other browsers. See below:
There are ways of handling long words and URLs using forced breaks, hyphenation, ellipsis, etc). See the terrific article here on the CSS Tricks website: https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/
What if you do not want a hyphen or ellipsis to appear? Using word-wrap: break-word; overflow-wrap: break-word; word-break: break-all; word-break: break-word; or even the Microsoft CSS Browser Prefix declaration -ms-word-break: break-all;, may not work. It didn’t for me.
The solution, using the HTML, ZERO-WIDTH-SPACE Unicode Character .
CSS
#container { width: 120px; background-color:#ccc; border: 1px solid #aaa; margin: 50px 50px 0; } .break { word-wrap: break-word; }
HTML
<div id="container"> <p>Donec sit amet erat porta, rhoncus dolor nec, <span class="break">scelerisqueaghtrafdssf</span> accumsan leo. Phasellus eu ipsum aliquam, <a class="break" href="www.samplewebsite.com/reallylongurl">www.reallylongwebsiteurl.com/reallylongurl</a> rutrum orci a, pulvinar elit. Aenean auctor dignissim tempus.</p> </div>
You have to insert the unicode character whereever you want the breaks to occur. See the final result below.
Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project?
Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of
Treehouse students and alumni in the community today.
Start your free trial
So I’m trying to do the very last exercise in the More Text Properties videos and I notice something funny.
word-wrap: break-word;
is not working for me. neither is
word-break:break-all;
I’m using Chrome 36.0.1985.143, any ideas on what I should do?
2 Answers
Awesome! No problem feel free to ask me questions if you have any other issues
Hi Aleksandra, can you post your code?