简体   繁体   中英

Bootstrap dropdown hidden by panel

Let's say I have a bootstrap panel on a page. Is there a way to have the contents of a dropdown fully visible within the panel. I'm having issues with the panel's overflow cutting off parts of my dropdowns. I don't want the panels to resize for their content, but rather to behave as you would expect from something like:

<div class="panel panel-default">
    <select>
        <option>...</option>
        ...
    </select>
</div>

Except with Bootstrap style drop-down content. Any suggestions?

If your panel is inside a panel-group you could overwrite de default overflow property. In Bootstrap core exists this rule:

.panel-group .panel {
    overflow:hidden;
}

so you should overwrite it:

.panel-group .panel {
    overflow:visible;
}

The z-index of the Bootstrap dropdown should allow it to overlay the panel..

http://www.bootply.com/Owj9ZxXgYL

<div class="panel panel-default">
    <div class="panel-heading">Title</div>
    <div class="panel-body">
        <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
          Menu
          <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li><a href="#">Choice1</a></li>
          <li><a href="#">Choice2</a></li>
          <li><a href="#">Choice3</a></li>
          <li class="divider"></li>
          <li><a href="#">Choice..</a></li>
        </ul>
      </div>
    </div>
</div>

Are you using some other dropdown?

I solved the problem by creating my own class that duplicated the look of the panel without the overflow being hidden. No matter what I did to the z-index, it didn't change the fact that the content was still hidden.

To reiterate what AaronF said, changing the z-index of the dropdown will not fix this problem. It has to do with the overflow:hidden property set by bootstrap on panels. I don't quite understand how it creates this problem, but if you add .panel-group .panel { overflow: visible; } .panel-group .panel { overflow: visible; } to your custom css, dropdowns will appear on top of panels as expected.

This could cause unknown side effects elsewhere in your app, so I would add a class selector before the .panel-group to keep it isolated to problem areas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM