1

I am trying to set custom width to the li element of bootstrap dropdown. I am tried various solutions on stack overflow but none of them worked in my case.

The HTML of the dropdown:

<span title="Settings" class="dropdown pull-right label label-primary" style="margin-top: 2px;margin-left: -2px;">
    <span class="glyphicon glyphicon-cog dropdown-toggle pointer" data-toggle="dropdown"></span>
    <ul class="dropdown-menu">
       <li class="cancel-proj-job" data-href="#">
          <a href="#">Cancel Project Job</a>
       </li>
    </ul>
</span>

Custom CSS:

.jOrgbody div#grid_col_mid .open>ul.dropdown-menu {
   font-size: 8px;
   padding: 0;
}

.jOrgbody div#grid_col_mid ul.dropdown-menu li {
   padding: 0;
}

.jOrgbody div#grid_col_mid ul.dropdown-menu li>a {
   padding: 0;
   display: inline-block;
}

issue_image1 issue_image2

Note: When I tried to apply fixed width to li. It didn't work. enter image description here

Community
  • 1
  • 1
Farjad Hasan
  • 3,354
  • 6
  • 23
  • 38

2 Answers2

1

The easiest way to do that is to do this is as i have done in following code:

<span title="Settings" class="dropdown pull-right label label-primary" style="margin-top: 2px;margin-left: -2px;">
<span class="glyphicon glyphicon-cog dropdown-toggle pointer" data-toggle="dropdown"></span>
<ul class="dropdown-menu">
   <li class="cancel-proj-job" data-href="#" style="width:300px;">
      <a href="#">Cancel Project Job</a>
   </li>
</ul>

change the "width:300px" to any length you want. Hope this helped.

edit: i have tried it in my browser with 100px and 300px nnd the result is as follows:

with width:100px; with width:300px;

P.RAO
  • 41
  • 8
0

I found the answer by debugging its css. Basically, the bootstrap has min-width:160px set for class dropdown-menu. I overwrite this value and li element start getting the custom width.

Farjad Hasan
  • 3,354
  • 6
  • 23
  • 38