【问题标题】:Applying CSS to Text inputs with Classes使用类将 CSS 应用于文本输入
【发布时间】:2010-09-19 19:49:56
【问题描述】:

我在我正在构建的表单上使用 jQuery 验证,它运行良好。我想要做的是当文本字段更改颜色并将错误消息变为白色时某些内容无效。我认为以下 CSS 会起作用:

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

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

CSS 似乎是有效的,因为当我离开 .error 子句时,一切看起来就像我想要的一样。我做错了什么?

【问题讨论】:

    标签: html css jquery-validate


    【解决方案1】:

    一个空格可能太多了。试试:

    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】:

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

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 2015-05-02
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2013-12-27
      • 2023-03-10
      • 1970-01-01
      • 2015-06-04
      相关资源
      最近更新 更多