我一直有这个问题,虽然我的解决方案是针对我自己的应用程序的,但你可能会发现它有用。
我的问题是我想要带有浅灰色悬停颜色的白色菜单文本。默认情况下,您遇到问题的内联 css 似乎采用您的菜单文本颜色,将其变亮一个因子并将该颜色设置为悬停颜色。显然白色不能变亮,所以我的菜单在悬停时保持不变。这是我解决这个问题的方法:
在位于 wp-content/themes/storefront_child/inc/customizer 的文件“class-storefront-customizer.php”中,定义了关于主题编辑器界面如何工作的函数。首先,我采用了以下功能:
public static function get_storefront_default_setting_values() {
return apply_filters( 'storefront_setting_default_values', $args = array(
'storefront_heading_color' => '#333333',
'storefront_text_color' => '#6d6d6d',
'storefront_accent_color' => '#aeaeae',
'storefront_header_background_color' => '#ffffff',
'storefront_header_text_color' => '#6d6d6d',
'storefront_header_link_color' => '#333333',
'storefront_footer_background_color' => '#f0f0f0',
'storefront_footer_heading_color' => '#333333',
'storefront_footer_text_color' => '#6d6d6d',
'storefront_footer_link_color' => '#333333',
'storefront_button_background_color' => '#eeeeee',
'storefront_button_text_color' => '#333333',
'storefront_button_alt_background_color' => '#333333',
'storefront_button_alt_text_color' => '#ffffff',
'storefront_layout' => 'right',
'background_color' => 'ffffff',
) );
}
我将 storefront_accent_color 变量设置为我想要的偏移颜色,在我的例子中是 #aeaeae。这会将默认颜色设置为编辑器的该值。此步骤不是必需的,但确实更容易。
我也将此选项设置为相同的值,因为我不确定哪个会真正生效...
$wp_customize->add_setting( 'storefront_accent_color', array(
'default' => apply_filters( 'storefront_default_accent_color', '#aeaeae' ),
'sanitize_callback' => 'sanitize_hex_color',
) );
该文件的第 501 行是函数 get_css() 的定义,它设置了您看到的要摆脱的内联 css。对我来说,我需要改变的值在这个部分:
.main-navigation ul li a:hover,
.main-navigation ul li:hover > a,
.site-title a:hover,
a.cart-contents:hover,
.site-header-cart .widget_shopping_cart a:hover,
.site-header-cart:hover > li > a,
.site-header ul.menu li.current-menu-item > a {
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_link_color'], 80 ) . ';
}
我把这个css属性的值改为:
color: ' . $storefront_theme_mods['accent_color'] . ';
这并没有改变悬停时偏移的设置颜色。然而,它所做的只是改变了编辑器。
所以最后一步是进入编辑器,进入排版选项卡,选择强调色,点击默认颜色按钮(现在应该作为我的颜色出现)然后保存。之后我的菜单运行良好。
这有点长,并不完全符合您的要求,但我将其全部用于说明如何操作输出到该内联 css 中的值。希望这些信息对您有所帮助。