Why do default buttons change color when borders are removed?

后端 未结 3 982
傲寒
傲寒 2021-01-13 14:15

As you can see from running the snippet below, the background color becomes darker when borders are removed. I guess it has something to do with background-color: butt

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 14:55

    In Chrome, the user agent stylesheet styles

It looks to me like Chrome is making an exception from how outset renders on buttons with a border-width of 2px, which happens to be the default border width set in user agent stylesheet.

For a full explanation on what's going on, read comments, see @Mukyuu's answer which, IMHO, is correct, and see this fiddle - forked from the one in comments.


Important: To be able to answer this type of CSS questions yourself, open Dev Console of Chrome (F12 or Ctrl/Cmd+I), select "Styles" side-tab:

, click on the element you want to inspect in the DOM tree (on left) and find the shorthand property in the Styles list. In your case, border: none;. You'll notice a small arrow after the the property name:

Click that arrow and you'll get the full list of what the browser parses it into.

That's how I got the information provided in this answer and my answer is true now. If standards change over time, it might become obsolete but, if you do as outlined above, you'll always get the currently "correct" answer.

提交回复
热议问题