Increase bootstrap dropdown menu width

前端 未结 7 798
悲哀的现实
悲哀的现实 2020-12-30 19:09

wondering if anyone has any tips on how to increase the dropdown width?

I have a row containing two columns with a a bit of javascript that slides the dropdown up an

相关标签:
7条回答
  • 2020-12-30 19:41

    Update 2018

    You should be able to just set it using CSS like this..

    .dropdown-menu {
      min-width:???px;
    }
    

    This works in both Bootstrap 3 and Bootstrap 4.0.0 (demo).


    A no extra CSS option in Bootstrap 4 is using the sizing utils to change the width. For example, here the w-100 (width:100%) class is used for the dropdown menu to fill the width of it's parent....

     <ul class="dropdown-menu w-100">
          <li><a class="nav-link" href="#">Choice1</a></li>
          <li><a class="nav-link" href="#">Choice2</a></li>
          <li><a class="nav-link" href="#">Choice3</a></li>
     </ul>
    

    https://www.codeply.com/go/pAqaPj59N0

    0 讨论(0)
  • 2020-12-30 19:42

    You can for example just add a "col-xs-12" class to the <ul> which holds the list items:

    <div class="col-md-6" data-toggle="dropdown">
                First column
                <ul class="dropdown-menu col-xs-12" role="menu" aria-labelledby="dLabel">
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                </ul>
            </div>
    

    This worked ok on any screen resolution in my site. The class will match the list width to it's containing div I believe:

    0 讨论(0)
  • 2020-12-30 19:47

    Text will never wrap to the next line. The text continues on the same line until a
    tag is encountered.

    .dropdown-menu {
        white-space: nowrap;
    }
    
    0 讨论(0)
  • 2020-12-30 19:53

    If you have BS4 another option could be:

    .dropdown-item { 
      width: max-content !important;
    }
    
    .dropdown-menu {
    
        max-height: max-content;
        max-width: max-content;
    }
    
    0 讨论(0)
  • 2020-12-30 20:02

    Add the following css class

    .dropdown-menu {
        width: 300px !important;
        height: 400px !important;
    }
    

    Of course you can use what matches your need.

    0 讨论(0)
  • 2020-12-30 20:04

    Usually the desire is to match the menu width to the width of the dropdown parent. This can be achieved easily like so:

    .dropdown-menu {
      width:100%;
    }
    
    0 讨论(0)
提交回复
热议问题