简体   繁体   English

下拉菜单无法显示隐藏溢出的 div

[英]dropdown cannot show over a div with hidden overflow

In my case, dropdown cannot show over the card cause the overflow is hidden, any solution?就我而言,下拉菜单无法显示在卡上,因为溢出被隐藏了,有什么解决方案吗? Pls find bellow the css and html and js for the hover effect of a section.请在下面找到 css 和 html 和 js 的 hover 效果部分。 the idea of this card is a card with some text details and a dropdown list and in the right a banner with hover effect to have some options, as on the phone when we swipe to the left to get delete or...这张卡片的想法是一张带有一些文本细节和一个下拉列表的卡片,右边是一个带有 hover 效果的横幅,有一些选项,就像在手机上当我们向左滑动来删除或...

 $(window).resize(function() { var $window = $(window); var windowsize = $window.width(); if (windowsize > 767) { $('.section2').hover( function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); } ); } }); $(window).trigger('resize'); $('.section2').bind('swiperight', function() { $('.section2').removeClass('hover'); }); $('.section2').bind('swipeleft', function() { $('.section2').removeClass('hover'); $(this).addClass('hover'); });
 .card { display: flex; width: 100%; background-color: white; border: 1px solid lightgray; border-radius: 8px; justify-content: space-between; align-items: center; padding: 20px; overflow: hidden; position: relative; transition: all ease.4s; height: 90px; margin-bottom: 100px; }.section1 { width: 95%; display: flex; flex-wrap: wrap; justify-content: space-between; }.dropdown { position: relative; display: inline-block; }.dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); padding: 12px 16px; z-index: 1; }.dropdown:hover.dropdown-content { display: block; }.section2 { position: absolute; top: 0; right: 0; height: 100%; z-index: 1; display: flex; transition: all ease.4s; transform: translateX(90%); background-color: purple; color: whitesmoke; }.section2.hover { transform: translateX(0%); }.section2 a { color: var(--white); text-decoration: none; display: inline-flex; width: 60px; height: 100%; margin-right: 0%; align-items: center; justify-content: center; transition: all ease.4s; }.section2 a:hover { color: var(--gray2); background-color: var(--gray1); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="card"> <div class="section1"> <div>Ipsus lupem ipsus lupem</div> <div class="dropdown"> <span>Mouse over me</span> <div class="dropdown-content"> <p>Hello World!</p> <p>Hello World!</p> <p>Hello World!</p> </div> </div> </div> <div class="section2"> <a href="">option1</a> <a href="">option2</a> <a href="">option3</a> <a href="">option4</a> </div> </div>

You need to remove position: relative from the ancestors.您需要从祖先中删除position: relative The combination of that and overflow: hidden is the cause of your problem.那和overflow: hidden是你的问题的原因。

 $(window).resize(function() { var $window = $(window); var windowsize = $window.width(); if (windowsize > 767) { $('.section2').hover( function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); } ); } }); $(window).trigger('resize'); $('.section2').bind('swiperight', function() { $('.section2').removeClass('hover'); }); $('.section2').bind('swipeleft', function() { $('.section2').removeClass('hover'); $(this).addClass('hover'); });
 .card { box-sizing: border-box; display: flex; width: 100%; background-color: white; border: 1px solid lightgray; border-radius: 8px; justify-content: space-between; align-items: center; padding: 20px; overflow: hidden; transition: all ease.4s; height: 90px; margin-bottom: 100px; }.section1 { width: 95%; display: flex; flex-wrap: wrap; justify-content: space-between; }.dropdown { display: inline-block; }.dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); padding: 12px 16px; z-index: 1; }.dropdown:hover.dropdown-content { display: block; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="card"> <div class="section1"> <div class="dropdown"> <span>Mouse over me</span> <div class="dropdown-content"> <p>Hello World!</p> <p>Hello World!</p> <p>Hello World!</p> </div> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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