How to view a dropdown menu of a button inside a div with overflow: Hidden?

Asked

Viewed 1,666 times

2

I have the following problem:

by clicking on the dropdown button inside a div with overflow property: Hidden it opens, but gets cropped. Example:

inserir a descrição da imagem aqui

HTML

<div class="scroll">
    <div class="out_element">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">
            Ação <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Ação</a></li>
          <li><a href="#">Outra ação</a></li>
          <li><a href="#">Algo a mais aqui</a></li>
          <li class="divider"></li>
          <li><a href="#">Link separador</a></li>
        </ul>
    </div>
</div>
    <div class="out_element">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">
            Ação <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Ação</a></li>
          <li><a href="#">Outra ação</a></li>
          <li><a href="#">Algo a mais aqui</a></li>
          <li class="divider"></li>
          <li><a href="#">Link separador</a></li>
        </ul>
    </div>
</div>
    <div class="out_element">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">
            Ação <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Ação</a></li>
          <li><a href="#">Outra ação</a></li>
          <li><a href="#">Algo a mais aqui</a></li>
          <li class="divider"></li>
          <li><a href="#">Link separador</a></li>
        </ul>
    </div>
</div>
    <div class="out_element">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">
            Ação <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Ação</a></li>
          <li><a href="#">Outra ação</a></li>
          <li><a href="#">Algo a mais aqui</a></li>
          <li class="divider"></li>
          <li><a href="#">Link separador</a></li>
        </ul>
    </div>
</div>
    <div class="out_element">
    <div class="btn-group">
        <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">
            Ação <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Ação</a></li>
          <li><a href="#">Outra ação</a></li>
          <li><a href="#">Algo a mais aqui</a></li>
          <li class="divider"></li>
          <li><a href="#">Link separador</a></li>
        </ul>
    </div>
</div>

</div>

CSS

body{
    height: 2000px;
}
.scroll{
    white-space: nowrap;
    width: 100%;
    overflow: auto;
    margin-top:100px;
}
.out_element{
    width: 200px;
    height: 100px;
    border: 1px solid #000;
    margin: 10px;
    display: inline-block;
}
ul.dropdown-menu{
    position:fixed;
    overflow:visible;
}

http://jsfiddle.net/VVVBk/3/ - Complete structure: http://jsfiddle.net/VVVBk/5/

How to solve this?

PS: I’m wearing a bootstrap;

  • No direct solution with CSS. A div father with overflow:hidden will always cut the child elements.

  • I understand @Kazzkiq - I had to use the abfurlan solution, gave it right!

3 answers

2

I don’t know the whole structure of your page, but follow a suggestion using position:fixed to the menu-dropdown:

ul.dropdown-menu{
    position: fixed;
    top: 10px;
    left: 20px;
    overflow: visible;
}

Example: Jsfiddle

With jQuery you can grab the position of the button clicked and assign to dropdown

$('button.dropdown-toggle').click(function(){
   var pos = $(this).offset(); //posição do elemento
   var alt = $(this).height(); //altura do elemento
   var w = $(window);
   //adiciona a posição que o elemento deve ficar corrigindo se houver scroll
   $(this).siblings('ul.dropdown-menu').css({"left":pos.left-  w.scrollLeft(),"top":pos.top+alt-w.scrollTop()});
});

//corrige a posição do elemento quando houver scroll
$(window).scroll(function(){
    var pos = $('.open>.dropdown-menu').siblings('button.dropdown-toggle').offset();
    var alt = $('.open>.dropdown-menu').siblings('button.dropdown-toggle').height();
    var w = $(window);
    $('.open>.dropdown-menu').css({"left":pos.left-w.scrollLeft(),"top":pos.top+alt-w.scrollTop()});
});
//para fechar qdo scroll div
$('.scroll').scroll(function(){
    $('.open>.dropdown-menu').dropdown('toggle');
});

Example: jQuery

  • My structure looks exactly like this: http://jsfiddle.net/VVVBk/5/ and is friendly responsive layout.

  • @Jeffersonalison edited the answer and added a solution in jQuery, see if it solves like this

  • That’s exactly what I want.. Only what you do is, roll the scroll with the dropdown open. It gets there :(

  • @Jeffersonalison I just edited Jsfiddle pq noticed this, see again http://jsfiddle.net/VVVBk/10/

  • That there @abfurlan, gave right here. Thanks man!

  • I found a problem.. That’s exactly what’s happening to me.. http://jsfiddle.net/VVVBk/12/ - of a scroll and then click or click and after a scroll to see what happens :(

  • @Jeffersonalison you are right, it is necessary to correct the position in the scroll, see how it got http://jsfiddle.net/VVBk/13/

Show 2 more comments

0

I think the ideal would be your div tab-content have a height fixed.

  • Can you give me an example Felipe?

  • I don’t know the full size of your container main. But, I did a test. height:500px in the div tab-content. Look here: http://jsfiddle.net/felipestoker/qPP4w/

  • It has a fixed size, including why I am working with columns and dragdrop pro user drag the element to which column he wants. Inside this element is the dropdown.

-1

Do you really need to set to Hidden? Have you tried resetting the property?

.scroll{ overflow: inherit; }

Update of your example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.