How do I disable form fields using CSS

0 votes

Can CSS be used to disable form fields? I'm aware of the attribute disabled, of course, but can I define it in a CSS rule? Something like -

<input type="text" name="username" value="admin" >
<style type="text/css">
  input[name=username] {
    disabled: true; /* Does not work */
  }
</style>

I'm asking because I have a program whose form fields are automatically produced and whose rules determine which fields should be hidden or displayed (which runs in Javascript). I now want to expand it to support disabling and enabling fields, however, the rules' current format directly modifies the form fields' style settings. Now that I have to alter the rule engine to change form field properties and styles, it doesn't seem ideal.

That you have visible and display attributes in CSS but can't enable or disable them is quite odd. Exists a similar feature in the HTML5 standard, which is currently being developed, or perhaps something non-standard (browser-specific)?

Aug 18, 2022 in CSS by Edureka
• 13,620 points

edited 4 days ago 4 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP