Skip to content Skip to sidebar Skip to footer

Css How To Wrap Text In Li

I'm trying to wrap my text in my slide menu. I have ul max-width 200px, but when I write longer text, then my text is not visible ( now i added overflow: visible to show You what I

Solution 1:

You can use word-wrap: break-word; on li. check updated snippet below..

.dropdown-menu li, .dropdown-menu li a {
    white-space: normal;
    float: left;
    width: 100%;
    height: auto;
    word-wrap: break-word;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-default" role="navigation">

<div class="dropdown">
    <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
        Dropdown
        <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" style="max-width: 200px" role="menu" aria-labelledby="dropdownMenu1">
        <li role="presentation" class="dropdown-header">Dropdown header trying to write something</li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
        <li role="presentation" class="disabled"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
        <li role="presentation" class="divider"></li>
        <li role="presentation" class="dropdown-header">Dropdown header</li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
    </ul>
</div>

</nav>

Solution 2:

Try this:

.dropdown-header {
  overflow-wrap: break-word;
  word-wrap: break-word;
  white-space: normal !important;
}

Solution 3:

Please try with this code

.dropdown-menu li, .dropdown-menu li a {
    word-break: break-word;
    white-space: normal;
}

Post a Comment for "Css How To Wrap Text In Li"