简体   繁体   English

Bootstrap工具提示和选择下拉重叠问题

[英]Bootstrap tool-tip and select drop-down overlap issue

I am working with layout that have tool-tip on label with select drop-down. 我正在使用带有选择下拉列表标签上的工具提示的布局。

Codepen Codepen

If we open drop-down and then hover on label for tool-tip both overlaps. 如果我们打开下拉列表,然后将鼠标悬停在标签上以便工具提示重叠。 I have tried giving max z-index to tool-tip but it is not working. 我已经尝试将max z-index赋予工具提示但它无法正常工作。

在此输入图像描述

The reason looks like tool-tip is having position-absolute and may be select drop-down is position fixed! 看起来像刀尖的原因是位置绝对可以选择下拉位置固定!

To inspect tooltip that keeps it open. 检查保持打开的工具提示

 $(function() { $('[data-toggle="tooltip"]').tooltip({ container: 'body' }); }); 
 .tooltip { z-index: 2147483647 !important; } 
 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div class="row"> <div class="col-md-2"> <div class="form-group"> <label data-toggle="tooltip" data-placement="bottom" title="Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, ipsum ratione, soluta veritatis iure earum impedit cumque animi aspernatur distinctio ad omnis. Id, doloribus accusamus nam cupiditate repellat officia aspernatur."> Label with tooltip </label> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> </select> </div> </div> </div> </div> 

As I said in the comment, I don't think you can change this behavior since it's handled by the browser. 正如我在评论中所说,我不认为你可以改变这种行为,因为它是由浏览器处理的。 One idea would be to remove the focus from the select on hover and make the dropdown disappear: 一个想法是从悬停选择中删除焦点并使下拉列表消失:

 $(function() { $('[data-toggle="tooltip"]').tooltip({ container: 'body' }).hover(function(){ $('select').blur(); }) }); 
 .tooltip { z-index: 2147483647 !important; } 
 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div class="row"> <div class="col-md-2"> <div class="form-group"> <label data-toggle="tooltip" data-placement="bottom" title="Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, ipsum ratione, soluta veritatis iure earum impedit cumque animi aspernatur distinctio ad omnis. Id, doloribus accusamus nam cupiditate repellat officia aspernatur."> Label with tooltip </label> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> </select> </div> </div> </div> </div> 

You can do it with CSS only: 你只能用CSS做到这一点:

[data-toggle=tooltip]:hover ~ select:focus{
  display:none;
}

 $(function() { $('[data-toggle="tooltip"]').tooltip({ container: 'body' }); }); 
 .tooltip { z-index: 2147483647 !important; } [data-toggle="tooltip"]:hover~select:focus { display: none; } 
 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div class="row"> <div class="col-md-2"> <div class="form-group"> <label data-toggle="tooltip" data-placement="bottom" title="Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, ipsum ratione, soluta veritatis iure earum impedit cumque animi aspernatur distinctio ad omnis. Id, doloribus accusamus nam cupiditate repellat officia aspernatur."> Label with tooltip </label> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> </select> </div> </div> </div> </div> 

You can hide the select element if you hover the tooltip Try it online 您可以隐藏选择元素,如果你悬停提示在线试玩

It's a workaround but if the tooltip covers the select this can be used 这是一种解决方法,但如果工具提示涵盖了选择,则可以使用

$( "label" ).hover(
  function() {
    $( "select" ).hide();
  }, function() {
    $( "select" ).show();
  }
);

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

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