Style <input> elements with a "readonly" attribute with CSS

CSSWeb DevelopmentFront End Technology

To select elements that are read-only, use the CSS :read-only selector.

Example

You can try to run the following code to implement the :read-only selector

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:read-only {
            background-color: blue;
            color: white;
         }
      </style>
   </head>
   <body>
      <form>
         Subject: <input type = "text" name = "subject" value = "Maths"><br>
         Student: <input type = "text" name = "student" readonly value = "Amit"><br>
      </form>
   </body>
</html>
raja
Published on 09-May-2018 11:23:51
Advertisements