Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very long words not wrapping in HTML/CSS

I have an issue where if a user was to enter a long comment/word such as 'cooooooooooooooooooooooooooooooooooooooool' this would break the formatting on the page.

Here is an image below to help explain the scenario (not to scale) and also the code used:

enter image description here

Html:

<div class="comment-content">
    <p>cooooooooooooooooooooooooooooooooooooooool</p>
    <br />
    <a class="delete-comment" data-delete-comment-id="28" href="/">Delete</a>
</div>

Css:

.comment-content
{
    width: 525px; 
    margin: 13px 25px 0 0;
}
.comment-content p
{
    width: 525px;
}

I am wondering if there is a quick fix for this without changing too much markup and CSS as this is area of code we would not want to introduce bugs by changing the application code (written in ASP.NET/MVC 3).

If CSS/Html was not an option I guess the HTML 5 <wbr> Tag could be used to seperate the word after 'x' amount of characters - the only issue with this is that the website is multi lingual in 9 languages. Japanese and Chinese for instance the text characters are significantly larger then English text characters which would need multiple conditional code for these to get the character count before adding the <wbr> or the font size decreased. Just after suggestions on the best solution really.

Many Thanks

like image 290
Danny Brady Avatar asked Dec 05 '12 11:12

Danny Brady


People also ask

How do you force text wrap in CSS?

You can force long (unbroken) text to wrap in a new line by specifying break-word with the word-wrap property. For example, you can use it to prevent text extending out the box and breaking the layout. This commonly happens when you have a long URL in the sidebar or comment list.


1 Answers

Try this

.comment-content p {
    word-wrap: break-word;
}

Live Demo

More Information

like image 110
Rohit Azad Malik Avatar answered Nov 04 '22 01:11

Rohit Azad Malik