我有这个下拉菜单设置,我遇到了麻烦。只要我使用子菜单,父链接就必须处于悬停状态。
/* Dropdown Button */
.dropbtn {
background-color: transparent;
color: #585558;
padding: 16px;
font-size: 1em;
border: none;
cursor: pointer;
font-weight: bold;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 1;
padding-top: -16px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: #585558;
padding: 6px 16px;
text-decoration: none;
display: block;
font-weight: bold;
}
.fb:hover {
color: #3b5998;
}
.ig:hover {
color: #fb3958;
}
.sc:hover {
color: #fffc00;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
.dropbtn:hover>a {
color: #ef5350;
}
.backslash {
color: #8e8e8e;
font-weight: bold;
}
<div class="dropdown">
<button class="dropbtn">Sociale medier</button>
<div class="dropdown-content">
<a class="fb" target="_blank" href="#">Facebook</a>
<a class="ig" target="_blank" href="#">Instagram</a>
<a class="sc" target="_blank" href="#">Snapchat</a>
</div>
</div>
使用子链接时如何让父链接保持悬停?
答案 0 :(得分:1)
您只需添加:hover
州。
.dropdown:hover .dropbtn {
background: aqua;
}
/* Dropdown Button */
.dropbtn {
background-color: transparent;
color: #585558;
padding: 16px;
font-size: 1em;
border: none;
cursor: pointer;
font-weight: bold;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
.dropdown:hover .dropbtn {
background: aqua;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 1;
padding-top: -16px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: #585558;
padding: 6px 16px;
text-decoration: none;
display: block;
font-weight: bold;
}
.fb:hover {
color: #3b5998;
}
.ig:hover {
color: #fb3958;
}
.sc:hover {
color: #fffc00;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
.dropbtn:hover>a {
color: #ef5350;
}
.backslash {
color: #8e8e8e;
font-weight: bold;
}
&#13;
<div class="dropdown">
<button class="dropbtn">Sociale medier</button>
<div class="dropdown-content">
<a class="fb" target="_blank" href="#">Facebook</a>
<a class="ig" target="_blank" href="#">Instagram</a>
<a class="sc" target="_blank" href="#">Snapchat</a>
</div>
</div>
&#13;