What is a user agent stylesheet?

后端 未结 14 571
无人及你
无人及你 2020-11-22 16:58

I\'m working on a web page in Google Chrome. It displays correctly with the following styles.

table {
    display: table;
    border-collapse: separate;
             


        
相关标签:
14条回答
  • 2020-11-22 17:21

    A user agent style sheet is a ”default style sheet” provided by the browser (e.g., Chrome, Firefox, Edge, etc.) in order to present the page in a way that satisfies ”general presentation expectations.” For example, a default style sheet would provide base styles for things like font size, borders, and spacing between elements. It is common to employ a reset style sheet to deal with inconsistencies amongst browsers.

    From the specification...

    A user agent's default style sheet should present the elements of the document language in ways that satisfy general presentation expectations for the document language. ~ The Cascade.

    For more information about user agents in general, see user agent.

    0 讨论(0)
  • 2020-11-22 17:21

    I had the same problem as one of my <div>'s had the margin set by the browser. It was quite annoying but then I figured out as most of the people said, it's a markup error.

    I went back and checked my <head> section and my CSS link was like below:

    <link rel="stylesheet" href="ex.css">

    I included type in it and made it like below:

    <link rel="stylesheet" type="text/css" href="ex.css">

    My problem was solved.

    0 讨论(0)
  • 2020-11-22 17:22

    Each browser provides a default stylesheet, called the user agent stylesheet, in case an HTML file does not specify one. Styles that you specify override the defaults.

    Because you have not specified values for the table element’s box, the default styles have been applied.

    0 讨论(0)
  • 2020-11-22 17:25

    If <!DOCTYPE> is missing in your HTML content you may experience that the browser gives preference to the "user agent stylesheet" over your custom stylesheet. Adding the doctype fixes this.

    0 讨论(0)
  • 2020-11-22 17:25

    Marking the document as HTML5 by the proper doctype on the first line, solved my issue.

    <!DOCTYPE html>
    <html>...
    
    0 讨论(0)
  • 2020-11-22 17:25

    Answering the question in title, what is the user agent stylesheet, the set of default styles in the browser: Here are some of them (and most relevant ones also in today's web):

    • Gecko (Firefox): https://dxr.mozilla.org/mozilla-central/source/layout/style/res/html.css

    • Chromium (Chrome): https://chromium.googlesource.com/chromium/src/third_party/+/master/blink/renderer/core/html/resources/html.css

    • WebKit (Safari): https://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css

    Personal opinion: Don't fight with them. They have good default values, for example, in rtl/bidi cases and are consistent nowadays. Reset what you see irrelevant to you, not all of them at once.

    0 讨论(0)
提交回复
热议问题