admin管理员组文章数量:1345733
I have a tooltip in a modal.
Is there a way that I can avoid the tooltip from being clipped by a container with overflow
on it?
I need the modal-dialog to handle content overflow so I cannot remove the overflow: auto
from it.
body {
margin: 0;
}
.container {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
}
.modal-dialog {
display: block;
height: 50%;
width: 50%;
background: cyan;
border: 1px solid;
overflow: auto;
}
.tooltip {
position: relative;
color: red;
text-decoration: underline;
}
.tooltip::after {
display: none;
content: 'Hello';
position: absolute;
left: -100%;
top: -100%;
height: 20px;
width: 60px;
}
.tooltip:hover::after {
display: inline-block;
background: black;
color: white;
}
<div class="container">
<div class="modal-dialog">
<span class="tooltip">Tooltip</span> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
</div>
</div>
I have a tooltip in a modal.
Is there a way that I can avoid the tooltip from being clipped by a container with overflow
on it?
I need the modal-dialog to handle content overflow so I cannot remove the overflow: auto
from it.
body {
margin: 0;
}
.container {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
}
.modal-dialog {
display: block;
height: 50%;
width: 50%;
background: cyan;
border: 1px solid;
overflow: auto;
}
.tooltip {
position: relative;
color: red;
text-decoration: underline;
}
.tooltip::after {
display: none;
content: 'Hello';
position: absolute;
left: -100%;
top: -100%;
height: 20px;
width: 60px;
}
.tooltip:hover::after {
display: inline-block;
background: black;
color: white;
}
<div class="container">
<div class="modal-dialog">
<span class="tooltip">Tooltip</span> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
</div>
</div>
Share
Improve this question
edited Oct 30, 2016 at 14:44
Michael Benjamin
373k110 gold badges613 silver badges730 bronze badges
asked Oct 17, 2016 at 19:00
takeraditakeradi
3,8718 gold badges30 silver badges56 bronze badges
1
-
can't you use
data-toggle="tooltip" title="your text"
? – Bhavin Shah Commented Oct 17, 2016 at 19:12
1 Answer
Reset to default 10The overflow: auto
rule will clip any content that overflows the container, as you have indicated. You would get a similar result with overflow: hidden
.
Because your tooltip pop-up (hover state) is absolutely positioned, and the nearest positioned ancestor is the tooltip trigger itself (position: relative
), and this trigger is within the container with overflow: auto
, there's no way to show the pop-up outside the container.
What you can do is make the nearest positioned ancestor an element higher up in the DOM structure. Then the abspos pop-up will reference that element, as opposed to the element with the overflow
.
body {
margin: 0;
}
.container {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
position: relative; /* moved here from .tooltip */
}
.modal-dialog {
display: block;
height: 50%;
width: 50%;
background: cyan;
border: 1px solid;
overflow: auto;
}
.tooltip {
color: red;
text-decoration: underline;
}
.tooltip::after {
display: none;
content: 'Hello';
position: absolute;
left: 15%; /* adjust as necessary */
top: 15%; /* adjust as necessary */
height: 20px;
width: 60px;
}
.tooltip:hover::after {
display: inline-block;
background: black;
color: white;
}
<div class="container">
<div class="modal-dialog">
<span class="tooltip">Tooltip</span> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque cupiditate ducimus, ea numquam est magnam quia ex consequuntur! Ratione modi dicta totam vel dolore, consequuntur nulla, amet labore odio voluptate!
</div>
</div>
本文标签:
版权声明:本文标题:javascript - Tooltip element with absolute positioning being clipped by container with overflow: auto - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743809366a2542778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论