gpt4 book ai didi

html - CSS Tooltip 悬停位置问题

转载 作者:行者123 更新时间:2023-11-28 18:50:22 26 4
gpt4 key购买 nike

我有一个直接的 CSS 悬停,但是,我遇到了 2 个问题:

1) 当它应该出现在缩略图正上方(居中)时,它却悬停在右边太远
2)它悬停在同一个地方,不管是哪个缩略图——它应该是相对于缩略图的位置,所以它会悬停在它正上方的中心

我已经试了好几次了,就是不让步。最初我把它包裹在一个......但是这是不可能的,因为悬停时的工具提示需要其中的文本链接..好老,'你不能在一个中有一个'问题。因此我使用了 .

必须在 CSS(最好)或 HTML 中进行哪些更改才能使此功能如上述两点中突出显示的那样?

代码

<html>
<head>
<style type="text/css">
a:link,
a:visited {
position:relative;
text-decoration:none;
}

a .tooltip img {
border:none;
}

.tooltip {
width:100px;
position:absolute;
bottom:100%;
margin:0 0 7px 0;
padding:15px;
font-weight:normal;
font-style:normal;
text-align:CENTER;
text-decoration:none;
text-shadow:0 1px 0 rgba(255,255,255,0.3);
line-height:1.5;
border:solid 1px;
-moz-border-radius:7px;
-webkit-border-radius:7px;
border-radius:7px;
-moz-box-shadow:
0 1px 2px rgba(0,0,0,0.3),
0 1px 2px rgba(255,255,255,0.5) inset;
-webkit-box-shadow:
0 1px 2px rgba(0,0,0,0.3),
0 1px 2px rgba(255,255,255,0.5) inset;
box-shadow:
0 1px 2px rgba(0,0,0,0.3),
0 1px 2px rgba(255,255,255,0.5) inset;
cursor:default;
display:block;
visibility:hidden;
opacity:0;
z-index:999;
-moz-transition:all 0.4s linear;
-webkit-transition:all 0.4s linear;
-o-transition:all 0.4s linear;
transition:all 0.4s linear;
}

.tooltip:before,
.tooltip:after {
width:0;
height:0;
position:absolute;
bottom:0;
margin:0 0 -20px -10px;
border:solid 10px;
border-color:transparent;
display:table-cell;
content:"";
}

.tooltip:before {
margin:0 0 -24px -12px;
border:solid 12px;
border-color:transparent;
z-index:-1;
}

/* hover */

span.tooltipwrapper:hover .tooltip {
text-decoration:none;
visibility:visible;
opacity:1;
-moz-transition:all 0.2s linear;
-webkit-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
transition:all 0.2s linear;
}



/* POSITIONS */

/* LEFT */

.tooltip,
.tooltip.left {
left:0;
right:0;
}

.tooltip:before,
.tooltip:after,
.tooltip.left:before,
.tooltip.left:after {
left:40px;
right:auto;
}


/* CENTER */

.tooltip.center {
left:50%;
right:auto;
margin-left:-65px;
}

.tooltip.center:before,
.tooltip.center:after {
left:50%;
right:auto;
}


/* RIGHT */

.tooltip.right {
left:auto;
right:0;
}

.tooltip.right:before,
.tooltip.right:after {
left:auto;
right:40px;
}

.tooltip.right:before {
margin-right:-2px;
}


/* SPEECH BUBBLE */

.speechbubble {
position:relative;
left:auto;
right:auto;
bottom:auto;
margin:0 0 12px 0;
cursor:text;
display:block;
visibility:visible;
opacity:1;
}


/* COLORS */

/* APPLE GREEN */

.tooltip.applegreen {
color:#445400;
background:#8DB600;
background:-moz-linear-gradient(top,rgba(141,182,0,0.8),rgba(141,182,0,1));
background:-webkit-gradient(linear,left top,left bottom,from(rgba(141,182,0,0.8)),to(rgba(141,182,0,1)));
border-color:#7C9902;
}

.tooltip.applegreen:before {
border-top-color:#7C9902;
}

.tooltip.applegreen:after {
border-top-color:#8DB600;
}
</style>
</head>
<body>
rollover images for larger view<br />
<span class="tooltipwrapper">
<img src="http://i3.kym-cdn.com/entries/icons/original/000/000/015/orly.jpg" alt="" width="20" height="20" />
<span class="tooltip center applegreen">
<img src="http://i3.kym-cdn.com/entries/icons/original/000/000/015/orly.jpg" alt="" width="80" height="80" />O RLY?<br/><a href="http://i3.kym-cdn.com/entries/icons/original/000/000/015/orly.jpg">Link to image</a>
</span>
</span>
<span class="tooltipwrapper">
<img src="http://thumbs.myopera.com/sz/colx/drlaunch/albums/37656/no-wai001.jpg" alt="" width="20" height="20" />
<span class="tooltip center applegreen">
<img src="http://thumbs.myopera.com/sz/colx/drlaunch/albums/37656/no-wai001.jpg" alt="" width="80" height="80" />NO WAI!!!<br/><a href="http://thumbs.myopera.com/sz/colx/drlaunch/albums/37656/no-wai001.jpg">Link to image</a>
</span>
</span>
</body>
</html>

最佳答案

position:relative 赋给您的.tooltipwrapper DIV,因为.tooltip绝对位置。像这样写:

.tooltipwrapper{
position: relative;
}

阅读本文了解更多 http://css-tricks.com/absolute-positioning-inside-relative-positioning/

关于html - CSS Tooltip 悬停位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9510710/

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