Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set color for disabled form elements #1403

Closed
wants to merge 1 commit into from
Closed

Set color for disabled form elements #1403

wants to merge 1 commit into from

Conversation

ArloL
Copy link

@ArloL ArloL commented Jul 10, 2013

Setting the color on form elements (e.g. button) also overwrites the disabled styles of the user agent: http://jsfiddle.net/rmHKu/1/

Therefore it is necessary to explicitly set the disabled style: http://jsfiddle.net/LfAUR/1/

Setting the color on form elements (e.g. button) also overwrites the disabled styles of the user agent: http://jsfiddle.net/rmHKu/1/

Therefore it is necessary to explicitly set the disabled style: http://jsfiddle.net/LfAUR/1/
@tchalvak
Copy link

Makes sense to me, as this is in main.css and not a normalize css feature. At least as long as this isn't a tweak that belongs in normalize.css .

@webhat
Copy link

webhat commented Jul 12, 2013

👍

@luanmuniz
Copy link

i really don't know if this belongs in main.css or normalize.css =/

@drublic
Copy link
Member

drublic commented Sep 7, 2013

This only needs to go into normalize.css when there is an inconsistency between browsers. Since normalize.css does not set any colors for inputs there is no need to overwrite them when disabled.

This change is a valid request and I think this is something we should tackle. Thanks for taking the time to do this Pull Request, @ArloL.

I've checked the default color of disabled links in Chrome and Firefox.
It seems like Chrome uses #545454 as the default for text (and those kind of) input fields. For buttons it uses graytext which is #808080 as you used. Firefox seems to use graytext for all disabled elements.

Maybe we need to research IE and Safari. Also mobile browsers would be relevant.
Otherwise I am good with merging this.

@alrra
Copy link
Member

alrra commented Sep 8, 2013

Android 4.1.2 (Samsung Galaxy S III)

Values

Browser input type="date" input type="datetime" input type="datetime-local" input type="email" input type="month" input type="number" input type="password" input type="search" input type="tel" input type="text" input type="time" input type="url" input type="week" textarea button input type="button" input type="file" input type="reset" input type="submit" select option optgroup
Default ¹ #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #808080 #808080 #000000 #808080 #808080 #808080 #808080 #808080
Chrome #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #808080 #808080 #545454 #808080 #808080 #808080 #808080 #808080
Firefox rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3) #b1a598 #b1a598

Screenshots

Browser Default ¹ Chrome Firefox
Screenshot

¹ default Android browser

iOS 6.1.3 (3rd generation iPad)

Values

Browser input type="date" input type="datetime" input type="datetime-local" input type="email" input type="month" input type="number" input type="password" input type="search" input type="tel" input type="text" input type="time" input type="url" input type="week" textarea button input type="button" input type="file" input type="reset" input type="submit" select option optgroup
Safari ¹ #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #808080 #808080 #000000 #808080 #808080 #808080 #808080 #000000

Screenshots

Browser Safari ¹
Screenshot

¹ Safari for iOS also uses opacity: 0.4000000059604645;, so that is why the perceived colors are different from the once specified above.

Mac OS X 10.8.4

Values

Browser input type="date" input type="datetime" input type="datetime-local" input type="email" input type="month" input type="number" input type="password" input type="search" input type="tel" input type="text" input type="time" input type="url" input type="week" textarea button input type="button" input type="file" input type="reset" input type="submit" select option optgroup
Chrome #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #7f7f7f #7f7f7f #545454 #7f7f7f #7f7f7f #808080 #7f7f7f #7f7f7f
Firefox #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f #000000 #7f7f7f #7f7f7f #7f7f7f #7f7f7f #7f7f7f
Opera #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #7f7f7f #7f7f7f #545454 #7f7f7f #7f7f7f #808080 #7f7f7f #7f7f7f
Safari #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000 #7f7f7f #7f7f7f #000000 #7f7f7f #7f7f7f #808080 #7f7f7f #000000

Screenshots

Browser Chrome Firefox Opera Safari
Screenshot

Ubuntu 13.04

Values

Browser button input type="text" input type="password" input type="button" input type="reset" input type="submit" input type="file" select option optgroup textarea
Chrome #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454
Firefox #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5
Opera ¹ #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5 #ada9a5

Screenshots

Browser Chrome Firefox Opera ¹
Screenshot

¹ On Ubuntu, the latest release of Opera is 12.16.

Windows 7

Values

Browser button input type="text" input type="password" input type="button" input type="reset" input type="submit" input type="file" select option optgroup textarea
Chrome #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454
Firefox #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d #6d6d6d
Internet Explorer 10 #707070 #707070 #707070 #707070 #707070 #707070 #707070 #707070 #707070 #707070 #707070
Opera #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454

Screenshots

Browser Chrome Firefox Internet Explorer 10 Opera
Screenshot

Windows XP

Values

Browser button input type="text" input type="password" input type="button" input type="reset" input type="submit" input type="file" select option optgroup textarea
Chrome #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454
Firefox #aca899 #aca899 #aca899 #aca899 #aca899 #aca899 #aca899 #aca899 #aca899 #aca899 #aca899
Opera #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454 #545454

Screenshots

Browser Chrome Firefox Opera
Screenshot

@drublic to get the above data, I've written this simple page (I didn't bother with IE6-8 because the :disabled pseudo-class is, as far as I know, only supported by IE9+, so you cannot change the color there anyway).

@mathiasbynens
Copy link
Member

Nice work, @alrra!

@necolas
Copy link
Member

necolas commented Sep 24, 2013

Yeah, nice research @alrra.

But I don't think there is anything to "fix" here. It's standard behaviour for the disabled styles to be affected once you start to add your own styles to the default form elements. All it takes is for someone to do something like .form .button { color: white } and you're right back at square one in terms of the disabled styles not displaying. It's just something that you have to deal with in your app/site code.

@necolas necolas closed this Sep 24, 2013
@alrra
Copy link
Member

alrra commented Sep 25, 2013

It's just something that you have to deal with in your app/site code.

Agree.


@drublic asked me in private to post whatever I've found regarding this, so here it is.

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    color: #808080;
}

The above won't work for all browsers. E.g.: on iOS 6/7 the text inputs become almost invisible due to the fact that Safari uses opacity: 0.4000000059604645;:

A better way, that works relatively decent in all browsers, is:

input:disabled,
textarea:disabled {
    color: #404040;
    opacity: .8;
}

button:disabled,
input[type="button"]:disabled,
input[type="reset"]:disabled,
input[type="submit"]:disabled,
optgroup:disabled, /* Only needed for Opera 12.16.*/
select:disabled {
    color: #808080;
    opacity: 1;
}          

Here is a test page, and the screenshots are below (first row: element --- second row: disabled element --- third row: disabled element with the above styles applied).

Also, note that: using opacity is quite performant.

Android 4.1.2 (Samsung Galaxy S III)

Browser Default ¹ Chrome Firefox
Screenshot

¹ default Android browser

iOS 7.0 (3rd generation iPad)

Browser Safari
Screenshot

Mac OS X 10.8.4

Browser Chrome Firefox Opera Safari
Screenshot

Ubuntu 13.04

Browser Chrome Firefox Opera ¹
Screenshot

¹ On Ubuntu, the latest release of Opera is 12.16.

Windows 7

Browser Chrome Firefox Internet Explorer 10 Opera
Screenshot

Windows XP

Browser Chrome Firefox Opera
Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants