请参阅下文,
边框应仅显示在悬停的<a>
标记上,但它会显示在嵌套
<a>
标记上
HTML
<ul><li>Home</li>
<li><a href='#'>About</a></li>
<li>
<a href='#'>Portfolio</a>
<ul>
<li><a href='#'>Web Design</a></li>
<li><a>Web Development</a></li>
<li><a>Illustrations</a></li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
CSS
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
background: #E3CAA1;
}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li:hover a {
border: 1px solid red;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
答案 0 :(得分:0)
试试这个:
ul li:hover > a {
border: 1px solid red;
}
&#34;&GT;&#34;意味着我们只与直接孩子建立关系,而不是嵌套孩子。
答案 1 :(得分:0)
将悬停链接更改为以下内容。
ul li li:hover a {
border: 1px solid red;
}
答案 2 :(得分:0)
如果您想仅在悬停的边缘设置边框,请替换代码
ul li:hover a {
border: 1px solid red;
}
<强>与强>
ul li a:hover {
border: 1px solid red;
}