多个 CSS 悬停弹出窗口可以在单个 div 中占据相同的空间吗?
我试图在菜单(列表项)中的不同行的悬停伪类上弹出文本跨度。 如果菜单/列表是水平的,我可以让弹出窗口在 div 中占据相同的空间,但垂直列表将弹出窗口放置在与“父”列表/菜单项相同的垂直高度处。
这是我迄今为止的相关代码:
<div id="greenback">
<div class="serviceframe">
<div class="serviceslist">
<ul>
<li><a href="">item 1<span>this is popup1.</span></a></li>
<p><li><a href="">item 2<span>This is popup 2's text but I want it to appear in exactly the same place as popup 1's text does.</span></a></li></p>
<p><li><a href="">item 3<span>same here - how can I get all popups positioned in exactly the same place?</span></a></li></p>
</ul>
</div><!-- closes serviceslist-->
</div><!-- closes serviceframe -->
</div><!-- closes greenback-->
CSS:
ul {
list-style: disc url(w-arrow.png) outside;
}
#greenback {
position: relative ;
top: 0em ;
width: 800px ;
height: 250px ;
background-color: #7EBB11 ;
border: 3px solid #112D82 ;
}
/*********SERVICE LIST MENU**********/
.serviceframe {
position: relative ;
width: 100% ;
height: 94% ;
background-color: #666666 ;
top: 3%; bottom: 3%;
}
/*--serviceframe is now sitting in greenback--*/
.serviceslist {
position: relative ;
width: 100% ;
height: 90% ;
top: 1% ;
background-color: #7EBB11 ;
font-family: Optima, Calibri, Candara, Century-Gothic,
Arial, sans-serif;
font-size: 100% ;
color: black ;
display: table-cell ;
vertical-align: middle ;
z-index: 100 ;
}
.serviceslist a
{position: relative;
display: table-cell; text-align: left; height: 100%; font: 1em sans-serif;
text-decoration: none; color: #112D82;
background: #7EBB11 ;
}
/*appearance of the <a> item (but before the <span> tag) on hover*/
.serviceslist a:hover {
color: white;
}
/*appearance of the spanned content within <a></a> tags when not hovered*/
.serviceslist a span {display: none;}
/*appearance of spanned content within <a> tags when hovered*/
.serviceslist a:hover span {
position: absolute;
display: table-cell;
margin-top: 0em; margin-left: -50%; z-index: 100;
width: 40%; height: auto; color: #FFFFFF; background-color: #7EBB11;
font: 14px Verdana, sans-serif; text-align: left;
}
I'm trying to have text spans pop up on a hover pseudo-class for different lines in a menu (list items). I can have the pop-ups occupy the same space in the div if the menu/list is horizontal, but a vertical list places the popups at the same vertical height as the "parent" list/menu item.
Here is the relevant code I have so far:
<div id="greenback">
<div class="serviceframe">
<div class="serviceslist">
<ul>
<li><a href="">item 1<span>this is popup1.</span></a></li>
<p><li><a href="">item 2<span>This is popup 2's text but I want it to appear in exactly the same place as popup 1's text does.</span></a></li></p>
<p><li><a href="">item 3<span>same here - how can I get all popups positioned in exactly the same place?</span></a></li></p>
</ul>
</div><!-- closes serviceslist-->
</div><!-- closes serviceframe -->
</div><!-- closes greenback-->
CSS:
ul {
list-style: disc url(w-arrow.png) outside;
}
#greenback {
position: relative ;
top: 0em ;
width: 800px ;
height: 250px ;
background-color: #7EBB11 ;
border: 3px solid #112D82 ;
}
/*********SERVICE LIST MENU**********/
.serviceframe {
position: relative ;
width: 100% ;
height: 94% ;
background-color: #666666 ;
top: 3%; bottom: 3%;
}
/*--serviceframe is now sitting in greenback--*/
.serviceslist {
position: relative ;
width: 100% ;
height: 90% ;
top: 1% ;
background-color: #7EBB11 ;
font-family: Optima, Calibri, Candara, Century-Gothic,
Arial, sans-serif;
font-size: 100% ;
color: black ;
display: table-cell ;
vertical-align: middle ;
z-index: 100 ;
}
.serviceslist a
{position: relative;
display: table-cell; text-align: left; height: 100%; font: 1em sans-serif;
text-decoration: none; color: #112D82;
background: #7EBB11 ;
}
/*appearance of the <a> item (but before the <span> tag) on hover*/
.serviceslist a:hover {
color: white;
}
/*appearance of the spanned content within <a></a> tags when not hovered*/
.serviceslist a span {display: none;}
/*appearance of spanned content within <a> tags when hovered*/
.serviceslist a:hover span {
position: absolute;
display: table-cell;
margin-top: 0em; margin-left: -50%; z-index: 100;
width: 40%; height: auto; color: #FFFFFF; background-color: #7EBB11;
font: 14px Verdana, sans-serif; text-align: left;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
天哪,对于一个简单的任务来说,这是一大堆 HTML 和 css。 我不会尝试通读所有内容,但只是给您答案
您只需要在 ul (或其上面的 div 之一)上有相对位置,因为这就是您想要使您的跨度绝对化的位置。
另外,删除 LI 周围的 P 标签。 UL 和 LI 之间不应该有任何东西。
My my, that's a whole lot of HTML and css for a simple task. I wont try to read through it all, but just give you your answer
You only need to have position relative on the ul (or one of the divs above it) because that's what you're wanting to make your spans absolute to.
Also, kill those P tags around your LIs. You shouldn't have anything between the UL and LI.
那么您希望所有不同的跨度出现在同一个地方吗?
您在 A 中设置相对位置,这使得跨度看起来与其“相对”。
修复:
锚。 // 不过,这似乎并不重要
FF 由于某种原因
跨度到所需值。
*你的代码片段不能在 IE6/7 上运行,所以我没有关心其中的错误。
So you want all the different spans to be appeared in the same place?
You set the relative position in A, which make the span appear "relative" to it.
Fix:
anchor. // Though, it doesn't seem to matter in
FF for some reason
span to desired value.
*Your code snippet doesn't work on IE6/7 so I didn't bother the bugs in it.