1

有什么想法可以让 LI 成为整个链接吗?

#nav{
position: relative;
width: 120px;
}
#nav a {
display: inline;
width: 100%
text-decoration: none;
}
#nav ul{
list-style-type: none;
}
#nav ul li{
background: #c0c0c0;
border-bottom: 1px dotted #404040;
}
#nav ul ul{
position: absolute;
left: 81px;
display: none;
}
#nav ul ul li{
background: #c0c0c0;
}
#nav ul li:hover ul{
display: inline;
}

这是链接: jsfiddle

我尝试过的选项:

  1. 一个{显示:块;} --> 这行得通,但第二个 UL 下降了。
  2. a {display: inline-block;} -->第二个 UL 问题已修复,但 LI 不是链接。
  3. 一个{显示:内联块;宽度:100%;高度:100%;} --> 与 2 相同。

提前致谢。

4

5 回答 5

2

It's because of the padding that it doesn't work. The element is actually overlapping the others.

#nav ul ul{
    position: absolute;
    top:0px;
    left: 80px;
    display: none;
    padding-left:0px;
}

You can find the full demo here: Working Demo

于 2013-03-23T07:54:23.397 回答
0
#nav a {
    display: block;
    text-decoration: none;
    float: left;
    width: 80px;
}

#nav ul li{
    background: #c0c0c0;
    border-bottom: 1px dotted #404040;
    overflow:hidden;
}

工作示例:http: //jsfiddle.net/wX2ss/16/

于 2013-03-23T07:49:36.097 回答
0

你需要改变这个CSS

    #nav a {
    display: block;
    text-decoration: none;
    }

你可以在这里查看

http://jsfiddle.net/wX2ss/30/

于 2013-03-23T07:50:58.693 回答
0

Try

#nav{
    position: relative;
    width: 120px;
}
#nav a {
    display: inline-block;
    text-decoration: none;
    width: 100%;
    background-color: lightblue;
}
#nav ul{
    list-style-type: none;
}
#nav ul li{
    background: #c0c0c0;
    border-bottom: 1px dotted #404040;
    position: relative;
}
#nav ul ul{
    position: absolute;
    left: 43px;
    display: none;
    top: 0;
}
#nav ul ul li{
    background: #c0c0c0;
}
#nav ul li:hover ul{
    display: inline;
}

Demo: Fiddle

于 2013-03-23T07:54:44.093 回答
0

试试这样

            #navbar ul li {
            display: inline;
            position: relative;
            }

            #navbar ul li ul  {
            position: absolute;
            visibility: hidden;
            }

            #navbar ul li:hover>ul {
            visibility: visible;
            position: absolute;
            display: block;
            }

            <div id="navbar">
                <ul>
                    <li><a href="link">1</a></li>
                    <li><a href="#">2</a>
                        <ul>
                            <li><a href="link">x</a></li>
                            <li><a href="link">y</a></li>
                            <li><a href="link">z</a></li>
                        </ul>
                    </li>
                    <li><a href="link">3</a></li>
                </ul>
            </div>
于 2013-03-23T08:03:27.847 回答