当滚动而不是仅滚动文本时,如何改变链接的整个背景?

问题描述 投票:0回答:2

我正在尝试使链接的整个长度更改背景颜色,但是只有文本后面的背景会更改。

html如下:

<DOCTYPE! HTML>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="dropdwn.css">
</head>

</body>

    <div class="dropdown">
        <h1><a href="#">Dropdown Box</a></h1>

            <ul class="content">
                <li><a href="#">List Item</a></li>
                <li><a href="#">List Item</a></li>
                <li><a href="#">List Item</a></li>
            </ul>

    </div>

</body>
</html>

CSS在下面,我尝试更改许多类的填充,但似乎无法获取。

body {
}

.dropdown {
    position: absolute;

}

.dropdown h1 {
    background-color: #62dbfc;
    font-family: "calibri light";
    padding: 15px 35px;
    margin: 0 auto;
    font-size: 36px;

}
.content {
    display: none;

}

.dropdown ul {
    margin: 0 auto;
    position: absolute;
    width: 100%;
    padding-left: 0;
}

.dropdown li {
    list-style-type: none;
    background-color: #ededed;
    margin: 0 auto;
    font-family: calibri;
    text-align: center;
    padding: 15px 0px;

}

.dropdown a {
    text-decoration: none;
    color: black;
    font-size: 36px;

}

.dropdown:hover .content {
    display: block;
}

.content a:hover {
    background-color: #c4c4c4; 

}
html css colors menu dropdown
2个回答
0
投票

更改要附加:hover的内容,它应突出显示整个li元素。

.content li:hover {
    background-color: #c4c4c4; 

}

-1
投票

尝试更改“ li”的背景颜色,而不是“ a”。您可以使用JQuery

$(".li_class").mouseover(function(){
  var color  = $(this).css("background-color");
  $(this).css("background", "#your color");
  $(this).mouseout(function(){
     $(this).css("background", color);
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.