How to style readonly attribute with CSS?

后端 未结 9 1649
忘了有多久
忘了有多久 2020-12-12 21:45

I\'m currently using readonly=\"readonly\" to disable fields. I\'m now trying to style the attribute using CSS. I\'ve tried using

input[readonly] {
/*styling         


        
9条回答
  •  天涯浪人
    2020-12-12 21:58

    Note that textarea[readonly="readonly"] works if you set readonly="readonly" in HTML but it does NOT work if you set the readOnly-attribute to true or "readonly" via JavaScript.

    For the CSS selector to work if you set readOnly with JavaScript you have to use the selector textarea[readonly].

    Same behavior in Firefox 14 and Chrome 20.

    To be on the safe side, i use both selectors.

    textarea[readonly="readonly"], textarea[readonly] {
    ...
    }
    

提交回复
热议问题