简体   繁体   English

将绝对元素定位在相对父容器之外

[英]Positioning absolute element outside of the relative parent container

I am trying to position the element(tooltip) outside of the parent element我试图将元素(工具提示)定位在父元素之外

code sample: You can see that when you hover on first li the tooltip is cut off.代码示例:您可以看到,当您将鼠标悬停在第一个 li 时,工具提示被切断。

 ul{ height: 200px; overflow: auto; } li{ position: relative; height: 40px; } .tooltip{ position: absolute; visibility: hidden; bottom: 45px; } li:hover > .tooltip{ visibility: visible; }
 <ul> <li>some data <span class="tooltip">Lots of data</span> </li> <li>some data2 <span class="tooltip">Lots of data</span> </li> ... ... </ul>

Ok, so in the above code, when you hower on the first li element the tooltip element is cut off by the container overflow: auto , The auto overflow has to be there as this ul element will contain lots of li and I want user to scroll through the list items.好的,所以在上面的代码中,当你在第一个li元素上使用时, tooltip元素被容器overflow: auto切断overflow: auto ,自动溢出必须在那里,因为这个ul元素将包含很多li ,我希望用户滚动列表项。

So my question is following: Is there a way to maintain the scroll behaviour of the ul element and at the same time to display the tooltip so that it is not cut off by the ul element?所以我的问题如下:有没有办法保持ul元素的滚动行为,同时显示工具提示,使其不被ul元素切断?

Any help is appreciated!任何帮助表示赞赏!

Use a containing element to apply scroll:使用包含元素来应用滚动:

 .list-wrapper { height: 100px; overflow: auto; padding-top: 30px; } li { position: relative; height: 40px; } .tooltip { position: absolute; visibility: hidden; bottom: 45px; } li:hover>.tooltip { visibility: visible; }
 <div class="list-wrapper"> <ul> <li>some data <span class="tooltip">Lots of data</span> </li> <li>some data2 <span class="tooltip">Lots of data</span> </li> <li>some data <span class="tooltip">Lots of data</span> </li> <li>some data2 <span class="tooltip">Lots of data</span> </li> <li>some data <span class="tooltip">Lots of data</span> </li> <li>some data2 <span class="tooltip">Lots of data</span> </li> <li>some data <span class="tooltip">Lots of data</span> </li> <li>some data2 <span class="tooltip">Lots of data</span> </li> </ul> </div>

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

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