Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word-wrap not working in LI element

I want to wrap the words automatically within width.

<ul class="dropdown-menu" style="width:298px;margin:15px 0 0 0;">
     <li>option 1 </li>
     <li>option 2 option 2 option 2 option 2 option 2 option 2</li>
</ul>

It's now working fine with white-space:normal

ul li{
     white-space:normal;
}
like image 753
user3322300 Avatar asked Feb 27 '14 07:02

user3322300


People also ask

How do you force text wrap in CSS?

Today I'm going to talk about a rarely used but extremely useful CSS property, the word-wrap. You can force long (unbroken) text to wrap in a new line by specifying break-word with the word-wrap property.

How do you break a long word in CSS?

The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line. word-break: break-all; It is used to break the words at any character to prevent overflow.

Can I use overflow-wrap anywhere?

The overflowing word that is otherwise unbreakable is broken into chunks of text using overflow-wrap: anywhere so that it fits in its container. It's important to note that anywhere is not yet supported by some browsers.


2 Answers

Please Try it...

ul li {
    word-break: break-all;
}
like image 139
Piyush Marvaniya Avatar answered Sep 25 '22 13:09

Piyush Marvaniya


Add white-space:normal to your CSS element:

  word-break: normal;
  white-space: normal;
like image 44
David M Avatar answered Sep 24 '22 13:09

David M