【问题标题】:How to change text color of the last two menus如何更改最后两个菜单的文本颜色
【发布时间】:2021-10-07 22:00:28
【问题描述】:

我想知道如何更改最后两个菜单的颜色,我想要的是将最后两个菜单使用白色而不是黑色。

网址:https://hrcstaging.wpengine.com/

最后两个菜单设计成一个按钮,我想把文字颜色改成白色。

【问题讨论】:

标签: 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;
        }
        

        【讨论】:

          猜你喜欢
          • 2021-03-28
          • 1970-01-01
          • 2019-04-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-06-28
          • 2011-03-31
          相关资源
          最近更新 更多