我看过其他类似的问题,但我无法将其应用于我的问题。我希望每个文本链接周围的框都是可单击的,而不仅仅是文本。

的HTML

<div class="container">
    <ul class="nav">
        <li class="nav-home">
            <a href="index.html">Home</a>
        </li>
        <li class="nav-games">
            <a href="games.html">Games</a>
        </li>
        <li class="nav-chat">
            <a href="chat.html">Chat</a>
        </li>
        <li class="nav-suggestions">
            <a href="suggestions.html">Suggestions</a>
        </li>
    </ul>
</div>


的CSS

.nav {
width: 900;
clear: right;
height: 55px;
margin-left: 22px;
margin-right: 22px;
padding: 0;
z-index: 5;
overflow: visible;
background: #161616;
background: -moz-linear-gradient(top,  #161616 0%, #282828 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#161616), color-stop(100%,#282828));
background: -webkit-linear-gradient(top,  #161616 0%,#282828 100%);
background: -o-linear-gradient(top,  #161616 0%,#282828 100%);
background: -ms-linear-gradient(top,  #161616 0%,#282828 100%);
background: linear-gradient(to bottom,  #161616 0%,#282828 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#161616', endColorstr='#282828',GradientType=0 );
border: 1px solid #090909;
box-shadow: inset 0px 0px 1px rgba(255,255,255,.2), 0px 3px 5px rgba(0,0,0,.5);
}

.nav li {
list-style-type: none;
float: left;
display: inline-block;
padding: 0px 89px;
width: 55;
text-align: center;
height: 55px;
border-right: 1px solid #090909;
box-shadow: 1px 0px 0px rgba(255,255,255,.1);
-webkit-transition:all 0.2s linear;
-moz-transition:all 0.2inear;
-o-transition:all 1s linear;
transition:all 0.2s linear;
}

.nav li.logo:hover { opacity: 1; background-color: transparent;}

.nav li:last-child { border: none; box-shadow: none; }


我在此处添加了display: block;,它使可单击的文本上方和下方但不在左侧或右侧。

.nav li a, nav ul li a:visited {
line-height: 55px;
text-decoration: none;
display: block;
color: #9c9c9c;
font-size: 15px;
font-family: "Droid Sans", Arial, sans-serif;
text-transform: uppercase;
text-shadow: 0px 1px 0px rgba(0,0,0,.9);
-webkit-transition:all 0.2s linear;
-moz-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
transition:all 0.2s linear;
}

.nav li:hover {
background-color: rgba(0,0,0,.2);
background-color: #191919\9;
-webkit-transition:all 0.2s linear;
-moz-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
transition:all 0.2s linear;
color: white;
}
.nav li:hover a { color: white;
-webkit-transition:all 0.2s linear;
-moz-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
transition:all 0.2s linear;
}

#nav-home .nav li.nav-home a, #nav-games .nav li.nav-games a, #nav-chat .nav li.nav-chat a,
#nav-comments .nav li.nav-comments a  { color: white; }


这是jsfiddle http://jsfiddle.net/U2d9X/3/的视觉效果。如果您能提供帮助,将不胜感激。如果需要更多信息或澄清,请询问而不是拒绝该问题。

最佳答案

1)从LI元素上删除左/右填充。

2)调整LI元素的宽度。

3)a { width: 100% !important; height: 100% !important; }

关于html - 导航栏上只有文本链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15390549/

10-09 20:26
查看更多