html - 简单的CSS飞出列表,有没有这么简单?

标签 html css

我的想法是,添加一个 anchor 标记并不难,当鼠标悬停或单击时,会导致出现包含更多链接的 CSS 弹出按钮。

就像现在一样,一组普通的 anchor 标记位于 li 内的 span 内。我想将此悬停弹出链接添加到与其中一个链接相同的位置,但不是普通链接,而是执行弹出链接。我在网上找到了各种代码,但在这个位置似乎都不起作用:

<li>
     Introduction to Something
     <span>
          <a target="_blank" href="http://http...file.html">Watch Slideshow</a>
          <a href="javascript:void(window.open('/file/853','file','height=650,width=1000,status=yes,toolbar=no,menubar=no,location=no'));">View File</a>
          <a target="_blank" href="http://file....pdf">Print</a>

          <a href="#">FLY OUT MENU ITEM</a>
     </span>
</li>

最佳答案

我已经在jsbin 发布了一个演示,它与@jeffkee 的回答没有太大区别。 , 以展示弹出菜单的深度和简单性。

(x)html 复制如下(带注释):

<ul>
    <li>home</li>
    <li>products
        <ul>
            <li><a href="#">CPUs</a>
                <ul>
                    <li><a href="#">AMD<a>
                        <ul>
                            <li><a href="#">AM2</a></li>
                            <li><a href="#">AM3</a></li>
                        </ul>
                    </li>
                    <li><a href="#">Intel</a></li>
                </ul>
            </li>
            <li><a href="#">Motherboards</a></li>
            <li><a href="#">PSUs</a></li>
            <li>Hard drives
                <ul>
                    <li><a href="#">HDD</a></li>
                    <li><a href="#">SSD</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li>Tracking</li>
</ul>

CSS 如下:

ul {list-style-type: none; width: 8em; border: 1px solid #000; padding: 0;}
/* just to set the base-line for the ul, but note the width. It's important. */

ul li {position: relative; border-top: 1px solid #000; margin: 0; padding: 0; }
/* the position: relative is used to allow its child elements to be absolutely positioned */

ul li:first-child {border-top: 0 none transparent; }
/* to avoid a two-pixel border on the first li (1px li-border + 1px ul-border) */

ul li:hover {background-color: #f90; }
/* just to aid visually */

ul ul {position: absolute; top: -1px; left: 8em; display: none; }
/* sets up all ul elements beneath the parent ul, the -px is to counter the movement forced by the border, bear in mind that the li:first-child doesn't *have* a border, so adjust to taste */

ul > li:hover > ul {display: block; }
/* makes the nested list appear if the parent-li is hovered */

关于html - 简单的CSS飞出列表,有没有这么简单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3790677/

相关文章:

html - 具有 href 属性的 Safari anchor 标签没有获得焦点?

html - 使用输入子项水平居中 div 和 span

javascript - 在 div 中查找 div

javascript - 背景图片的CSS3定时动画

html - 防止CSS改变元素宽度

html - :before psuedo element changes into share icon怎么办

javascript - for 循环中的 if 语句同时执行,而不是只执行一个

javascript - JQuery 示例不起作用 - "Object doesn' t 支持属性或方法 'button'“

html - CSS:为同一父级分配固定宽度的 div 以及百分比分配的 div。

php - 移动设备发出的 HTML 表单必填字段