如何修改购物车按钮的:active状态颜色?
问题描述
我的网站购物车按钮点击后会变成深蓝色,这是Elementor后台设置的主按钮颜色,但我试了好几段带!important的CSS代码,都没法覆盖这个点击后的样式。

网站地址:https://www.umowydlabiurarachunkowego.pl/homen
我尝试过的CSS代码(均未生效):
.elementor-menu-cart__toggle.elementor-button { background-color: #ffffff00 !important; }
.elementor-menu-cart__toggle_button.elementor-button.elementor-size-sm:active { background-color: #ffffff00 !important; }
.eicon-basket-medium:active { background-color: #ffffff00 !important; }
解决方案
你之前的问题主要是选择器不精准或者优先级不够,试试下面这段CSS:
.elementor-menu-cart__toggle.elementor-button:active, .elementor-menu-cart__toggle.elementor-button:focus { background-color: transparent !important; /* 你要的透明背景 */ /* 如果需要调整边框或文字颜色,可添加以下两行 */ /* border-color: #你的颜色值 !important; */ /* color: #你的颜色值 !important; */ }
为啥之前的代码没用?
- 第二段代码里的类名写错了:
elementor-menu-cart__toggle_button是错误的,正确类名是elementor-menu-cart__toggle,多了个_button导致匹配不到元素。 - 第三段代码只改了图标
eicon-basket-medium的背景,但按钮的背景样式是设置在父级按钮元素上的,改图标没用。 - 第一段代码没指定点击后的状态(
:active/:focus),只能改按钮默认状态,覆盖不了点击激活后的样式。
内容的提问来源于stack exchange,提问作者Łukasz Wójcik
相关产品推荐
相关产品推荐

