CSS Selector for <input type=“?”

前端 未结 4 1497
Happy的楠姐
Happy的楠姐 2020-11-28 21:54

Is there any way with CSS to target all inputs based on their type? I have a disabled class I use on various disabled form elements, and I\'m setting the background color fo

4条回答
  •  失恋的感觉
    2020-11-28 22:37

    Yes. IE7+ supports attribute selectors:

    input[type=radio]
    input[type^=ra]
    input[type*=d]
    input[type$=io]
    

    Element input with attribute type which contains a value that is equal to, begins with, contains or ends with a certain value.

    Other safe (IE7+) selectors are:

    • Parent > child that has: p > span { font-weight: bold; }
    • Preceded by ~ element which is: span ~ span { color: blue; }

    Which for

    would effectively give you:

    Further reading: Browser CSS compatibility on quirksmode.com

    I'm surprised that everyone else thinks it can't be done. CSS attribute selectors have been here for some time already. I guess it's time we clean up our .css files.

提交回复
热议问题