<style>
/* CSS for the span */
.hover {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 100%;
left: 96%;
margin-left: -60px;
}
/* CSS for the text containing the span */
.imagetest {
position: relative;
}
/* CSS for text on hover */
.imagetest:hover .hover {
visibility: visible;
display:inline-block;
}
</style>
PHP/HTML
<?php
echo "<div class='hoverText' align=right><img class='imagetest' src='Files/infoplaceholder.png' height=20 width=20><span class='hover'> See About Page for more info </span></div>";
echo "<BR>";
?>
当我将交换名称放在 css 部分时,imagetest
for hoverText
工作得很好。该方法的缺点是 div 横跨整个页面,鼠标光标经过 div 的任何地方都会弹出悬停。悬停只是不喜欢我存储在图像上的类。我想知道这是为什么。
最佳答案
您的 CSS 正在尝试选择“.imagetest”的子元素,该元素具有“悬停”类。由于 span.hover 标签不是 .imagetest 的子标签,css 不会选择它。
尝试这样的事情
<div class='hoverText' align=right>
<span class='imagetest'>
<img src='Files/infoplaceholder.png' height=20 width=20 />
<span class='hover' > See About Page for more info </span>
</span>
</div>
这将帮助 CSS 找到内部跨度作为 .imagetest 的子元素
另一种选择是使用 CSS 选择器来选择 sibling
.imagetest:hover + .hover {
visibility: visible;
display: inline-block;
}
关于php - 文本显示在图像悬停上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50686043/