【问题标题】:Can multiple CSS hover popups occupy the same space within a single div?多个 CSS 悬停弹出窗口可以在单个 div 中占用相同的空间吗?
【发布时间】:2008-12-18 11:47:50
【问题描述】:

我正在尝试在菜单(列表项)中的不同行的悬停伪类上弹出文本跨度。如果菜单/列表是水平的,我可以让弹出窗口在 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;
    }

【问题讨论】:

  • 您能重新格式化代码吗?它很难阅读(每个代码行缩进四个空格,以便在 stackoverflow 上阅读)。
  • 我已经为他/她编辑了格式
  • 大声笑,我们都为他编辑格式...:D
  • 谢谢 - 首次用户问题 ;)

标签: css popup modalpopups


【解决方案1】:

我的天,对于一个简单的任务来说,这是一大堆 HTML 和 css。我不会试图通读它,但只是给你你的答案

<ul>
  <li><a href="">item 1<span>this is popup1.</span></a></li>
  <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>
  <li><a href="">item 3<span>same here - how can I get all popups positioned in exactly the same place?</span></a></li>
</ul>

ul { position: relative; }
ul span { position: absolute; }

您只需要在 ul(或它上面的 div 之一)上具有相对位置,因为这就是您想要使您的跨度绝对的位置。

另外,杀死你的 LI 周围的那些 P 标签。你不应该在 UL 和 LI 之间有任何东西。

【讨论】:

  • 谢谢,它似乎没有任何区别(至少在 FF 中),但我会在其他人身上尝试。 P 标签只是为了给我一些节奏并且不会影响结果,但无论如何我已经把它们拿出来了。干杯帕特里克。
  • @patrick - 为了简单起见,我删除了很多 css,但是在那些带有 top/left 声明的地方设置相对位置和绝对位置肯定会起作用。
【解决方案2】:

所以你想让所有不同的跨度出现在同一个地方吗? 您在 A 中设置了相对位置,这使得跨度看起来与它“相对”。

修复:

  • 删除相对定位 锚。 // 不过,这似乎并不重要 FF 出于某种原因
  • 为 跨度到所需的值。

*你的代码 sn-p 在 IE6/7 上不起作用,所以我没有打扰它。

【讨论】:

  • 非常感谢,让 a:hover 条件成为定义位置的条件是一种享受。如此合乎逻辑......这是我的第一个 CSS,所以我边走边学。我想在 FF/Sf 1st 中把它弄好,然后修复 IE(这样我就可以先完成一件事情!) - 一个好方法还是没有?帕特里克干杯。
  • 这是一种常用的方法,因为 IE6 是如此古怪。我相信使用百分比高度,会让你的 sn-p 在 IE 中出错。
猜你喜欢
  • 2023-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-18
  • 2022-12-19
相关资源
最近更新 更多