Twitter bootstrap dropdown goes outside the screen

后端 未结 8 1114
失恋的感觉
失恋的感觉 2021-01-30 00:14

I want to implement twitter bootstrap dropdown menu, here\'s my code:

 


        
相关标签:
8条回答
  • 2021-01-30 00:55

    I can't leave a comment because my SO level is too low, but I just made sure that the parent container is set to "overflow:hidden" like so (also make sure position is set).

    <div style="overflow:hidden;position:relative">
        <span class="dropdown"> 
        <a href="#menu1" class="dropdown-toggle" data-toggle="dropdown" ><img class="left" src="/static/img/topmenu_preferences.png" /><b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><a href="#">a</a></li>
          <li><a href="#">b</a></li>
          <li><a href="#">c</a></li>
          <li class="divider"></li>
          <li><a href="#">d</a></li>
        </ul>
    </div>
    
    0 讨论(0)
  • 2021-01-30 00:59

    float-*-right for Bootstrap 4

    * = xs, sm, md, lg

    0 讨论(0)
  • 2021-01-30 01:04

    in Bootstrap 4 you can use .dropleft

    just change to :

    <span class="dropleft">

    or

    add .dropdown-menu-{lg,med,sm,xs}-right to your dropdown-menu

    <div class="dropdown-menu dropdown-menu-sm-right" aria-labelledby="dropdown03">
        <a class="dropdown-item" href="#">Action</a>
        <a class="dropdown-item" href="#">Another action</a>
        <a class="dropdown-item" href="#">Something else here</a>
    </div>
    
    0 讨论(0)
  • 2021-01-30 01:05

    adding .pull-right to ul.dropdown-menu should do it

    Deprecation Notice: As of Bootstrap v3.1.0, .pull-right on dropdown menus is deprecated. To right-align a menu, use .dropdown-menu-right.

    0 讨论(0)
  • 2021-01-30 01:06

    For Bootstrap 4, adding dropdown-menu-right works. Here's a working example..

    http://codeply.com/go/w2MJngNkDQ

    0 讨论(0)
  • 2021-01-30 01:11

    You can use class .dropdown-pull-right with following css:

    .dropdown-pull-right {
      float: right !important;
      right: 0;
      left: auto;
    }
    
    .dropdown-pull-right>.dropdown-menu {
      right: 0;
      left: auto;
    }
    <link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"/>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
    
    
    <div class="dropdown dropdown-pull-right btn-group">
      <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
      Open Dropdown
      <span class="caret"></span>
      </a>
      <ul class="dropdown-menu">
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
      </ul>
    </div>

    0 讨论(0)
提交回复
热议问题