我試圖在我的代碼頁上顯示一個工具提示,我嘗試在 css 中添加 z-index,但它沒有用,我嘗試將顯示更改為 inline-block 但仍然相同。
這是我的代碼:
.tooltip {
position: relative;
display: inline-block;
background-color: transparent;
border-width: 0px;
margin: 0px;
padding: 0px;
float: none;
z-index: 9999999
}
.tooltip .tooltiptext {
visibility: hidden;
width: 355px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
opacity: 0;
transition: opacity 1s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="tooltip">
<i class="fa fa-info-circle"></i>
<span class="tooltiptext">Hello nice to meet u!</span>
</div>
</body>
以下圖片是我可以看到的

uj5u.com熱心網友回復:
你只需要處理定位,看看我的例子,我剛剛添加了 position:absolute 和 top 和 left 屬性,對我來說看起來不錯,當你“強制狀態”時,你可以很容易地使用 dev-tools 元素檢查器徘徊”
.tooltip {
position: absolute;
display: inline-block;
background-color: transparent;
border-width: 0px;
margin: 0px;
top:40px;
left:40px;
padding: 0px;
float: none;
z-index: 9999999
}
.tooltip .tooltiptext {
visibility: hidden;
width: 355px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
opacity: 0;
transition: opacity 1s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="tooltip">
<i class="fa fa-info-circle"></i>
<span class="tooltiptext">Hello nice to meet u!</span>
</div>
uj5u.com熱心網友回復:
改變 .tooltip .tooltiptext { bottom: 125%; }。
片段:
.tooltip {
position: relative;
display: inline-block;
background-color: transparent;
border-width: 0px;
margin: 0px;
padding: 0px;
float: none;
z-index: 9999999
}
.tooltip .tooltiptext {
visibility: hidden;
width: 355px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
/*bottom: 125%;*/
left: 50%;
opacity: 0;
transition: opacity 1s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="tooltip">
<i class="fa fa-info-circle"></i>
<span class="tooltiptext">Hello nice to meet u!</span>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/346569.html
上一篇:如果我縮小視窗而不是在移動設備上,為什么我的斷點有效?
下一篇:顯示空結果的下拉選單
