【发布时间】:2019-05-18 15:38:53
【问题描述】:
图像是父 div,子 div 位于一个小的 图像的一部分(父)。孩子是我要悬停的div 并让工具提示下拉,但是当我悬停时工具提示会下拉 图像(父)。我不会真正使用 HTML 和 css,所以请原谅 任何新手的错误。我找到了工具提示的大部分代码 各种网站。我实在是太过分了!!!
我从网上下载了 sn-ps。试图把 在一起,只是经验不够。
/* I do not understand the css, but after several
weeks of research this is what I have. The Image
seems to be placed correctly and is the right size.
*/
body {
text-align: center;
}
.tooltip {
position: relative;
display: inline-block;
border-bottom: none;
}
/* The tooltip is in fact hidden.*/
.tooltip .tooltiptext {
visibility: hidden;
width: 290px;
background-color: #ffcc99;
color: #000;
text-align: left;
border-radius: 6px;
padding: 5px 0;
margin-left: 10px;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 0px;
left: 110%;
}
/* Tooltip becomes visible when hover
over the big Image. */
.tooltip:hover .tooltiptext {
visibility: visible;
}
/* I added this to the sample I downloaded. It
sizes the Image correctly, and locates it
where I want it on the Webpage.
*/
#container {
position: absolute;
width: 330px;
height: 240px;
border: 5px, #000;
border-style: solid;
margin: auto;
margin-top: 10px;
left: 40px;
top: 20px;
}
#container img {
width: 100%;
height: 100%;
}
/* This creates the child div. I have located it
over the area on the Image where I want the
tooltip to become visible. I put a border
around the child so I can see where it is.
*/
.dropdown {
position: absolute;
width: 226px;
height: 23px;
border: 1px, #000000;
border-style: solid;
background: transparent;
left: 45px;
top: 15px;
}
/* The below code is where I am really not sure how to use. The tooltip drops down when I hover the Image. I cannot make it so that it only drops when I hover the child. I will send a screenshot if I can figure out how to do so. */
<h2>The Best Tooltip</h2>
<p>Move the mouse over the Image below:</p>
<div class="tooltip"> <img src="MMDVM_Pic.jpg" alt="#">
<div class="dropdown">
<span class="tooltiptext"><b><center>More Information About Date and
Time</center></b>
<p style="margin-left:10px; margin-right:10px">This shows the <font
color=”#050778A”;><b>Date and Time </b></font>as reported by <font
color=”#ff0000”;><b>pistar.</b></font> There are several <font
color=”#E0E614”;>formats</font> supported.</p>
</div>
</div>
【问题讨论】:
-
您显示的 HTML 存在有效性问题(未关闭
span,错误关闭div元素)。 -
您正在对父级应用 :hover 效果,而不是对子级
-
Alon,请注意,当您悬停子项(黑色矩形)时,工具提示变为可见。当您将鼠标悬停在父级(小图标)时,它也会变得可见。阻止它从父悬停下拉是问题所在。谢谢。
-
@MitchSavage 然后将
<div>下拉菜单作为悬停的父级,而不是将其应用于父级并期望子级获得事件,除非您希望在 JavaScript 中得到答案