我有一个悬停此按钮的问题,当我在#search-button中传递光标时,我无法使.icon-search变为白色。
.icon-search {
fill: #868585;
width: 20px
}
.icon-search {
margin: 0 20px;
}
#search-button {
border-radius: 0px 2px 2px 0px;
border-color: #303030 !important;
background-color: #343434;
border: 2px solid;
cursor: pointer;
outline: none;
}
#search-button,
.icon-star:hover {
fill: white;
color: white
}
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
<button id="search-button" type="submit"><svg aria-hidden="true" class=
"icon icon-search" height="28" viewbox="0 0 26 28" width="26" xmlns=
"http://www.w3.org/2000/svg">
<path d=
"M18 13c0-3.859-3.141-7-7-7s-7 3.141-7 7 3.141 7 7 7 7-3.141 7-7zm8 13c0 1.094-.906 2-2 2a1.96 1.96 0 0 1-1.406-.594l-5.359-5.344a10.971 10.971 0 0 1-6.234 1.937c-6.078 0-11-4.922-11-11s4.922-11 11-11 11 4.922 11 11c0 2.219-.672 4.406-1.937 6.234l5.359 5.359c.359.359.578.875.578 1.406z">
</path></svg></button>
</body>
</html>
强文
我希望光标通过.icon-search,#search-button变成白色。
答案 0 :(得分:1)
我改变了你的css并且它有效。您的代码中有逗号:#search-button,.icon-star:hover
和:hover
应添加到#search-button
。另外,在您的CSS而不是.icon-search
中添加了.icon-star
。这可以防止图标在按钮悬停时更改颜色。
请注意,我缩小了代码并离开了问题所需的内容。
#search-button {background-color:#343434}
#search-button .icon-search {
fill: #868585;
width: 20px;
margin: 0 20px;
}
#search-button:hover .icon-search {
fill: white;
}
<button id="search-button" type="submit">
<svg aria-hidden="true" class="icon icon-search" height="28" viewbox="0 0 26 28" width="26">
<path d="M18 13c0-3.859-3.141-7-7-7s-7 3.141-7 7 3.141 7 7 7 7-3.141 7-7zm8 13c0 1.094-.906 2-2 2a1.96 1.96 0 0 1-1.406-.594l-5.359-5.344a10.971 10.971 0 0 1-6.234 1.937c-6.078 0-11-4.922-11-11s4.922-11 11-11 11 4.922 11 11c0 2.219-.672 4.406-1.937 6.234l5.359 5.359c.359.359.578.875.578 1.406z"></path>
</svg>
</button>