gpt4 book ai didi

html - 如何防止工具提示文本显示在具有相对定位的相邻 div 下?

转载 作者:太空宇宙 更新时间:2023-11-04 07:41:05 25 4
gpt4 key购买 nike

我有两个 div,它们包含一个输入框和一个图标,当鼠标悬停在上面时会显示工具提示文本。由于我需要让 div 相互堆叠,因此它们具有“position:relative;”。当我将鼠标悬停在第一个工具提示图标上时,工具提示文本太大而无法包含在其包装器 div 中。然而,文本并没有完全可见,而是被掩埋在第二个包装 div 下。

我希望我的视觉设计与实际设计完全一样,唯一的区别是工具提示位于当前隐藏它的 div 之上。有什么办法可以在不对我的代码进行大修的情况下解决这个问题吗?

https://jsfiddle.net/jlcollier/nw45knLy/1/

HTML:

    <!DOCTYPE html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="inputblock">
<input class="inputseperate" type="text" name="a"><br>
<div class="help-tip">
<p>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa</p>
</div>
</div>
<div class="inputblock">
<input class="inputseperate" type="text" name="b"<br>
<div class="help-tip">
<p>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb</p>
</div>
</div>
</body>
</html>

CSS:

    .inputseperate {
width:70%;
}

.inputblock {
margin-bottom:30px;
width:100%;
background-color: #ccc;
border-radius: 5px 5px 5px 5px;
position: relative;
}

.help-tip{
position: absolute;
top: 0px;
right: 5px;
text-align: center;
background-color: #333;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
}

.help-tip:before{
content:'?';
font-weight: bold;
color:#fff;
}

.help-tip:hover p{
display:block;
transform-origin: 100% 0%;
}


.help-tip p{
display: none;
text-align: left;
background-color: #1E2021;
padding: 20px;
width: 300px;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
right: -4px;
color: #FFF;
overflow: visible;
font-size: 13px;
line-height: 1.4;
}

.help-tip p:before{
position: absolute;
content: '';
width:0;
height: 0;
border:6px solid transparent;
border-bottom-color:#1E2021;
overflow: visible;
right:10px;
top:-12px;
}

.help-tip p:after{
width:100%;
height:40px;
content:'';
position: absolute;
overflow: visible;
top:-40px;
left:0;
}

最佳答案

z-index 属性添加到 .help-tip

fiddle

.inputseperate {
width: 70%;
}

.inputblock {
margin-bottom: 30px;
width: 100%;
background-color: #ccc;
border-radius: 5px 5px 5px 5px;
position: relative;
}

.help-tip {
position: absolute;
top: 0px;
right: 5px;
text-align: center;
background-color: #333;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
z-index: 1;
}

.help-tip:before {
content: '?';
font-weight: bold;
color: #fff;
}

.help-tip:hover p {
display: block;
transform-origin: 100% 0%;
}

.help-tip p {
display: none;
text-align: left;
background-color: #1E2021;
padding: 20px;
width: 300px;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
right: -4px;
color: #FFF;
overflow: visible;
font-size: 13px;
line-height: 1.4;
}

.help-tip p:before {
position: absolute;
content: '';
width: 0;
height: 0;
border: 6px solid transparent;
border-bottom-color: #1E2021;
overflow: visible;
right: 10px;
top: -12px;
}

.help-tip p:after {
width: 100%;
height: 40px;
content: '';
position: absolute;
overflow: visible;
top: -40px;
left: 0;
}
<div class="inputblock">
<input class="inputseperate" type="text" name="a"><br>
<div class="help-tip">
<p>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa<br>aaaaaaaaa</p>
</div>
</div>
<div class="inputblock">
<input class="inputseperate" type="text" name="b" <br>
<div class="help-tip">
<p>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb<br>bbbbbbbbb</p>
</div>
</div>

关于html - 如何防止工具提示文本显示在具有相对定位的相邻 div 下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48509604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com