【发布时间】:2021-11-29 10:52:26
【问题描述】:
我想创建这个悬停效果:
基本上,当悬停其子元素中的特定元素时,阻止白色部分变暗。
这是我的 HTML 代码:
<div className= {css.searchBarDiv}>
<div className={css.searchBarContent}/>
<div className={css.searchBarButton}>
<div className={css.button}>
<Image/>
</div>
</div>
</div>
这是我对 CSS 代码的尝试:
.searchBarDiv {
&:hover {
background-color: #e7e7e7;
}
&:focus-within {
background-color: #ffffff;
box-shadow: rgb(0 0 0 / 20%) 0px 6px 20px;
}
}
.searchBarButton {
flex: 0 0 auto;
margin-left: -6px;
padding-right: 9px;
align-self: center;
}
.button {
max-width: 200px;
animation-delay: 0.8s;
background-color: #ee3465;
color: #ffffff;
cursor: pointer;
&:hover {
text-decoration: none;
color: #ffffff;
background-color: #df3562;
}
}
【问题讨论】:
-
尝试从 .searchBarDiv 中移除 &:hover
-
您可以将悬停效果分配给 .searchBarContent 而不是父项吗?我假设输入字段在 .searchBarContent 元素内。而圆形按钮是兄弟姐妹。
-
我找不到它是哪种语言。请告诉
css预处理器和html预处理器 -
并将 css 更改为 scss ,less 或您正在使用的东西
-
@Musafiroon 它刚刚在 REACT 中完成,class 而不是 className 将使其适用于常规代码。
标签: javascript html css reactjs