英文:
How to override property overflow:hidden for custom tooltip?
问题
我试图覆盖属性overflow:hidden
(父td
元素)
我的工具提示应该显示在我的td
元素下面:
工具提示的代码:
.tooltip1 {
text-decoration: none;
overflow: visible !important;
}
.tooltip1:hover {
position: relative;
}
.tooltip1 span {
display: none;
}
.tooltip1:hover span {
border: #666 2px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: #e3e3e3;
left: 0px;
margin: 15px;
width: 150px;
position: absolute;
top: 15px;
text-decoration: none;
overflow: visible !important; //not working
}
HTML代码:
<div class="tooltip1">Link
<span>CSS工具提示在鼠标悬停在链接上时显示</span>
</div>
结果:
但我需要像这样的效果(工具提示在所有单元格上方):
我需要以某种方式禁用或覆盖td
元素的属性overflow:hidden
,以便我无法只更改父td
元素的属性。
英文:
I am trying to override property overflow:hidden (parent td element)
for my tooltip which should be shown under my td element:
Code for tooltip:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.tooltip1 {
text-decoration: none;
overflow: visible !important;
}
.tooltip1:hover {
position: relative;
}
.tooltip1 span {
display: none;
}
.tooltip1:hover span {
border: #666 2px dotted;
padding: 5px 20px 5px 5px;
display: block;
z-index: 100;
background: #e3e3e3;
left: 0px;
margin: 15px;
width: 150px;
position: absolute;
top: 15px;
text-decoration: none;
overflow: visible !important; //not working
}
<!-- language: lang-html -->
<div class="tooltip1">Link
<span>CSS tooltip showing up when your mouse over the link</span>
</div>
<!-- end snippet -->
Result:
But I need something like this(tooltip above all cells):
I need somehow disable or override the property of td overflow:hidden for [.tooltip1:hover span] (our tooltip), so I can't just change if for parent td element.
答案1
得分: 1
我猜测工具提示是 td 元素的子元素。如果是这样,您可以通过使用 :has()
来覆盖溢出属性:
td:has(.tooltip1:hover) {
overflow: visible;
}
以下是一个示例:
<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->
<!-- 语言:lang-css -->
.td {
width: 50px;
overflow: hidden;
}
.td:has(.tooltip:hover) {
overflow: visible;
}
<!-- 语言:lang-html -->
<div class="td">
<div class="tooltip">
sdfksdfksdfksdfksdfsdfksdfk
</div>
</div>
<!-- 结束代码片段 -->
英文:
I'm guessing the tooltip is a child of the td. If so, you can override the overflow property by using has()
:
td:has(.tooltip1:hover) {
overflow: visible;
}
Here is an example:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.td {
width: 50px;
overflow: hidden;
}
.td:has(.tooltip:hover) {
overflow: visible;
}
<!-- language: lang-html -->
<div class="td">
<div class="tooltip">
sdfksdfksdfksdfksdfsdfksdfk
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论