对不起,我不知道如何解释这个问题,我有一个带有href链接的菜单栏,但是当它悬停在项目框时它怎么能像徘徊在链接一样?
ul li a:link{color:#0F0F0F;text-decoration:none;}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 10px 20px;
background: #fff;
color:#2A0851;
cursor: pointer;
border-bottom:8px solid black;
border-left:1px solid grey;
}
ul li a:hover {
color: #929292;
background-color:#000000;
}
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;
border-bottom:solid 1px white;
-webkit-transiton: opacity 0.2s;
}
ul li ul li:hover { background: #000;}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li:first-child {
border-left: none;
}

<ul>
<li ><A href="https://www.google.com.my/">apple</A></li>
<li ><A href="https://www.google.com.my/">apple</A></li>
<li ><A href="https://www.google.com.my/">apple</A></li>
<li ><A href="https://www.google.com.my/">apple</A></li>
<li ><A href="https://www.google.com.my/">apple</A></li>
<li ><A href="https://www.google.com.my/">apple</A></li>
</ul>
&#13;
预期结果:当悬停在超链接区域外时,菜单栏背景颜色会发生变化,也可以从超链接外部点击。
答案 0 :(得分:2)
你的意思是这样的? 您希望整个按钮改变颜色而不是链接文本吗?
ul li a:link{color:#0F0F0F;text-decoration:none;}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
background: #fff;
color:#2A0851;
cursor: pointer;
border-bottom:8px solid black;
border-left:1px solid grey;
}
ul li:hover {
color: #929292;
background-color:#000000;
}
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;
}
a {
padding: 10px 20px;
}
ul li ul li
{
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
border-bottom:solid 1px white;
-webkit-transiton: opacity 0.2s;
}
ul li ul li:hover { background: #000;}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li:first-child {
border-left: none;
}
a { display: block; padding: 10px 20px; }
<ul>
<li><a onclick="alert('click!');" >apple</a></li>
<li><a onclick="alert('click!');" >apple</a></li>
<li><a onclick="alert('click!');" >apple</a></li>
<li><a onclick="alert('click!');" >apple</a></li>
<li><a onclick="alert('click!');" >apple</a></li>
<li><a onclick="alert('click!');" >apple</a></li>
</ul>
答案 1 :(得分:0)
修改您的css样式,如下所示:
ul li{
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 10px 20px;
border-bottom: 8px solid black;
border-left: 1px solid grey;
cursor: pointer;
background: #2A0851;
}
ul li a{
font: bold 12px/18px sans-serif;
color: #fff;
}