Is there a CSS selector for elements lacking an attribute?

后端 未结 4 462
一整个雨季
一整个雨季 2021-02-04 23:44

I understand that css rules can target elements specified by attribute values, e.g.:

input[type=\"text\"] {}

Can I make a rule that targets ele

相关标签:
4条回答
  • 2021-02-04 23:47

    For links you can simply use:

    a { color: red; }
    a:link { color: green; }
    

    fiddle: http://jsfiddle.net/ZHTXS/ no need for javascript.

    For form attributes, use the not attribute pattern noted above input:not([type]) and if you need to support older versions of IE, I'd probably add a class and use an IE specific style sheet linked with conditional comments.

    0 讨论(0)
  • 2021-02-04 23:52

    You can always set different style to a and a href

    Check this: http://jsfiddle.net/uy2sj/

    0 讨论(0)
  • 2021-02-04 23:54

    You can follow this pattern:

    a:not([href])
    input:not([type])
    

    The attribute selector is used to select elements with the specified attribute.

    :not is supported in all modern browsers and IE9+, if you need IE8 or lower support you're out of luck.

    0 讨论(0)
  • 2021-02-05 00:06

    The only solution that worked for me was to place a:link { } within my code.

    I also tried

    a:not([href]) input:not([href=""]) input:not([href~=""])

    But for a .scss file with multiple a tags used as standard code blocks (not my idea), this was the only solution.

    0 讨论(0)
提交回复
热议问题