Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the <li> item width fit the text length?

How can I make the <li> item width fit the text length in Bootstrap 3? My menu item is shorter than the text which causes my class="active" to look ugly.

This is the navbar in which it occurs:

<div id="menu" class="col-md-1">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#">Startseite</a></li>
<li><a href="kontakt.php">Kontakt</a></li>
</ul>
</div>
like image 209
CodeShark Avatar asked Feb 02 '14 15:02

CodeShark


People also ask

How do I make a div fit text?

You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).

How do I change the width of a Li in HTML?

You'd have to work on your code because you can't assign widths to inline elements. But this can be solved by setting the display to block and by floating it.

How do you fit text in a box in CSS?

You have to set 'display:inline-block' and 'height:auto' to wrap the content within the border. Show activity on this post. Two ways are there. No need to mention height in this it will be auto by default.


1 Answers

make a .custom_li class and give

.custom_li{
   display:inline-block;
}

EDIT

To force same size, i'll suggest using max-width and place it under some media-query

li{
    display: inline-block;
    max-width:50%; /* limit width */
    word-break:break-all; /* wrap extended text*/
    border:1px solid red /* demo */
}

demo here

some optional things

some optional things

like image 54
NoobEditor Avatar answered Oct 06 '22 08:10

NoobEditor