Reputation: 4610
I am using bootstrap 3 to create a simple drop-down menu, but I want to decrease its width and I can't figure it out how to do this.
HTML:
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Action</a></li>
<li><a href="#">Another</a></li>
<li><a href="#">Something</a></li>
<li><a href="#">Separated</a></li>
</ul>
</div>
CSS:
.dropdown-menu {
width: 60px !important;
}
Upvotes: 5
Views: 14850
Reputation: 1270
Give a ID for the div and specify the min-width in the css as follows:
.dropdown #mydiv{ min-width:60px; }
Note: Do NOT use '!important'. For more information check out this great post by Chris Coyier : Specifics on CSS Specificity
Upvotes: 0
Reputation: 8695
.dropdown-menu
has min-width: 160px;
and min-width
overrides width
so you can not change width
you can use min-width
instead of width
.
.dropdown-menu {
min-width: 60px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Action</a>
</li>
<li><a href="#">Another</a>
</li>
<li><a href="#">Something</a>
</li>
<li><a href="#">Separated</a>
</li>
</ul>
</div>
It works. You should call bootstrap lib
and jquery
. Please, read bootstrap documentation.
Upvotes: 12