Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does changing the `background-color` of a button change other styles too?

Tags:

css

http://codepen.io/anon/pen/KwKOaz

Changing only the background-color significantly changes the style on a button element, specifically the border style.

background change

This happens on chrome, safari, and firefox on a Mac. Why does this happen? How can I safely change its background color?

like image 719
fent Avatar asked Nov 17 '14 22:11

fent


People also ask

What is the use of changing the background color of a text?

Checking Color Contrast. Changing the color and background color of text is also essential for avoiding problems of web accessibility on your website.

What is the property for changing the background color?

The background-color property sets the background color of an element. The background of an element is the total size of the element, including padding and border (but not the margin). Tip: Use a background color and a text color that makes the text easy to read.

Can we change the color of a button more than once?

Explanation: We can change by dyind it with different colours.


2 Answers

Browser vendors apply custom styling to UI elements like buttons and input fields. Altering one of these overwritten attributes results in disabling all of the other vendor styles on that element as well. If you want to change one attribute, you have to alter the others as well, I'm afraid.

Unfortunately I can't tell you why they do this - probably there is might be some spec behind, but I cannot find any evidence for that.

like image 125
Christoph Avatar answered Oct 25 '22 09:10

Christoph


When all the styles are untouched, the browser uses the host OS's given API to render the given control. This will make the control look native to the platform, but if you apply any style to that control/element, the browser cannot guarantee that the given style can be applied in the given platform, so it defaults back to a simplified, fully css solution.

Also note, that styling control elements, though works, not covered by stable standards yet.

For example, the NSButton (native control behind the button in OS X) doesn't have an option to set the background color, so the browser faces an impossible task. On Windows, you can change the background color, this is why people report not seeing your issue on Windows.

like image 36
Zenorbi Avatar answered Oct 25 '22 10:10

Zenorbi