【问题标题】:How to change text color of the last two menus如何更改最后两个菜单的文本颜色
【发布时间】:2021-10-07 22:00:28
【问题描述】:
【问题讨论】:
标签:
html
css
wordpress
menu
wordpress-theming
【解决方案1】:
如果您想要一种比使用 ID 更动态的方法,并且您的菜单将保留相同数量的列表项,您可以使用伪类。 :nth-child 应该可以工作。 :nth-of-type 也可能有效,但我会使用 :nth-child。
#menu-primary-menu li:nth-child(7) a, #menu-primary-menu li:nth-child(8) a { color: white }
或
#menu-primary-menu li:nth-of-type(7) a, #menu-primary-menu li:nth-of-type(8) a { color: white }
在您的情况下,如果 ID 永远不会改变,这是最简单的方法,但一般来说了解伪类是件好事。
【解决方案2】:
li#menu-item-4779 a, li#menu-item-4780 a {
color: white;
font-weight: bold;
}
谢谢大家,我得到了代码,现在运行良好
【解决方案3】:
请为您的按钮添加两个具有相同名称的类。做
.white{
color: #fff;
}
<button class='white'>Verify Insurance</button>
<button class='white'>(704)-970-4106</button>
提到按钮标签可以是任何具有自定义属性的 html 元素。例如,它可以是一个标签。
您也可以将#fff 代码替换为颜色名称,因为#fff 是白色十六进制代码。
【解决方案4】:
您可以为这些元素添加一个 ID 并向它们添加一个 CSS 属性。
HTML:
<a id="white-link" href="#">Verify Insurance</a>
<a id="white-link" href="#">Number</a>
CSS:
a#white-link {
color: white;
}
Demo
【解决方案5】:
将此 css 添加到您的 css 文件中。
.main-navigation .main-nav ul li:nth-last-child(2) a,.main-navigation .main-nav ul li:last-child a{
color:#fff;
}
【解决方案6】:
你可以使用css
button{
color: #fff;
}
或者按钮类,在这种情况下是
.btnClass{
color: #fff;
}