Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling disabled <select> (dropdown boxes) in HTML

Tags:

One of our customers has a hard time reading the grey text in disabled controls in our web-based application:

IE9 example

We would like to change the style to a light grey background and a black text. Unfortunately, most browsers (including IE, which is what the customer is using) ignore the color: ... CSS attribute on disabled controls, so we cannot change the foreground color.

For text boxes (input type="text"), this can easily be workarounded by using the readonly instead of the disabled attribute. Unfortunately, this is not an option for dropdowns (select) or checkboxes (input type="checkbox").

Is there an easy workaround for that? Preferebly one where the control does not need to be replaced by another type of control? (...since our controls are rendered by ASP.NET)

PS: Using the [disabled] selector in CSS does not make a difference.

like image 564
Heinzi Avatar asked Sep 30 '10 10:09

Heinzi


People also ask

How do you make a drop down disabled in HTML?

We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element. A disabled drop-down list is un-clickable and unusable.

How do I style a dropdown in HTML?

HTML) Use any element to open the dropdown content, e.g. a <span>, or a <button> element. Use a container element (like <div>) to create the dropdown content and add whatever you want inside of it. Wrap a <div> element around the elements to position the dropdown content correctly with CSS.

Can you style a select element?

<select> tags can be styled through CSS just like any other HTML element on an HTML page rendered in a browser.


2 Answers

In Internet Explorer 9, support will be added for the :disabled pseudo-selector (ref). I don't know whether that will honor the "color" property, but it seems likely.

In older versions of IE, you can adjust the background color (but not the color). Thus:

    <style type="text/css">         select[disabled] { background-color: blue; }     </style> 

That works in IE 7 and IE 8. You still can't alter the foreground color, but you can change the background color to contrast more strongly with the gray that IE assigns it when it's disabled.

like image 165
Will Martin Avatar answered Oct 29 '22 23:10

Will Martin


This worked for me in webkit and Firefox

select:disabled{    opacity: 0.6; } 
like image 39
Darren Cooney Avatar answered Oct 29 '22 23:10

Darren Cooney