Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I style a disabled control using CSS or script?

Tags:

html

jquery

css

I have a HTML div element on a page that is updated when a select element on the page changes. Sometimes the input tags (text boxes) need to be disabled based on the selection.

Here is the problem: the project stakeholders like the functionality, they just think in the "disabled" state, the text box contents are too light and therefore unreadable. Can I apply CSS to a disabled control? Or should I be setting the text boxes to readonly and using some other CSS. This application is also using jQuery, if that helps. And ideas or suggestions here?

like image 866
Hcabnettek Avatar asked Dec 08 '09 15:12

Hcabnettek


People also ask

Can we disable button using CSS?

To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.

How do you make a Div disabled using CSS?

An element can be disabled in HTML by setting disable property to true and enabled again by setting disabled=false. By using jQuery, you can grab the element you want to enable or disable and change this property by using the prop() or attr() function, depending upon the version of jQuery you are using.

How do I make labels disabled in HTML?

First step: swap the HTML elements order so that the <label> appears after the <input> . This will allow the styling rules to work as desired. Then for the fun bit: use CSS to position the labels for text inputs on the left hand side! input[type=radio]:disabled+label works like a sharm!


1 Answers

input[type="submit"][disabled="disabled"]
{
    /* CSS here */
}
input[type="text"][disabled="disabled"]
{
    /* CSS here */
}
input[type="button"][disabled="disabled"]
{
    /* CSS here */
}

Works in every browser if the input tag is something like:

<input type="submit" disabled="disabled">

and if you want to change it when it is not disabled, just add this to your CSS

input[type="submit"]
{
    /* CSS here */
}
input[type="text"]
{
    /* CSS here */
}
input[type="button"]
{
    /* CSS here */
}
like image 78
Carlos Avatar answered Sep 20 '22 23:09

Carlos