我想用两个类来改变这个按钮的图标,'saved'和'removed'。我已经定义了如下样式,但是当只使用'saved'或'removed'时,样式不能正确显示,我找不到原因。请指导我。
index.js
<button class="icon-btn has-state saved" aria-label="Add to saved recipes">
<span class="material-symbols-outlined bookmark-add" aria-hidden="true" >bookmark_add</span>
<span class="material-symbols-outlined bookmark-add" aria-hidden="true" >bookmark</span>
</button>
字符串
style.css
.has-state {
position: relative;
overflow: hidden;
}
.has-state::after {
content: "";
position: absolute;
inset: 0;
transition: var(--transition-short);
}
.has-state:where(:hover, :focus-visible):not(:active)::after {
background-color: var(--alpha-10);
}
.material-symbols-outlined {
display: block;
width: 1em;
height: 1em;
overflow: hidden;
font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}
.saved .bookmark-add,
.removed .bookmark {
display: none;
}
.saved .bookmark {
font-variation-settings: "FILL" 1;
}
.icon-btn {
width: 40px;
height: 40px;
display: grid;
place-items: center;
background-color: var(--primary-container);
border-radius: var(--radius-circle);
}
型
1条答案
按热度按时间ego6inou1#
假设“样式显示不正确”是为了传达这样一个事实,即当
saved
在<button>
上时没有图标出现,那么看起来你可能想让类bookmark
在第二个<span>
上,而不是bookmark-add
上:个字符