代码之家  ›  专栏  ›  技术社区  ›  dragonmantank

将CSS应用于带有类的文本输入

  •  1
  • dragonmantank  · 技术社区  · 18 年前

    我正在构建的表单上使用jquery validate,它工作得很好。我要做的是,当某些内容无效时,让文本字段更改颜色,错误消息为白色。我认为下面的CSS可以工作:

    label .error {color: white; font-weight: bold;}
    input .error {background-color: pink; border: 1px dashed red; color: white}
    

    当我测试验证时,上面的CSS似乎不适用。我使用Firebug进行了检查,标签和输入区域应用了“错误”类。

    当我离开.error子句时,css似乎有效。所有东西看起来都像我想要的一样。我做错什么了?

    2 回复  |  直到 18 年前
        1
  •  11
  •   Tomalak    18 年前

    一个空间可能太大。尝试:

    label.error {color: white; font-weight: bold;}
    input.error {background-color: pink; border: 1px dashed red; color: white}
    

    背景信息:

    label .error  /* selects all elements of class "error" *within* any label */
    label.error   /* selects labels of class "error"                          */
    
        2
  •  3
  •   Dave    18 年前

    尝试label.error和input.error,不带空格。