What is a user agent stylesheet?

后端 未结 14 573
无人及你
无人及你 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:27

    I just wanted to expand on the response from @BenM based on what I read here from Ire Aderinokun. Because the user-agent stylesheet provides helpful default styling, think twice before overriding it.

    I had a dumb error where a button element didn't look right in Chrome. I had partially styled it because I didn't want it to look like a traditional button. However, I left out style elements like border, border-color, etc. So Chrome was stepping in to supply the parts that it thought I was missing.

    The problem went away once I added styles like border: none, etc.

    So if anyone else is having this problem, make sure you are explicitly overriding all the applicable default user-agent styles for an element if you notice it looks wonky, especially if you don't want to reset the user agent styles completely. It worked for me.

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

    I ran into this same issue, it was because I was working with non-semantic html

    <!--incorrect-->
    <ul class="my-custom-font">
      <button>
        <a>user agent styles applied instead of my-custom-font</a>
      <button>
    </ul>
    
    <!--correct-->
    <ul class="my-custom-font">
      <li>
        <a>now inherits from from my-custom-font</a>
      </li>
    </ul>
    

    Once the HTML was updated, styles were applied correctly

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

    What are the target browsers? Different browsers set different default CSS rules. Try including a CSS reset, such as the meyerweb CSS reset or normalize.css, to remove those defaults. Google "CSS reset vs normalize" to see the differences.

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

    Some browsers use their own way to read .css files. So the right way to beat this: If you type the command line directly in the .html source code, this beats the .css file, in that way, you told the browser directly what to do and the browser is at position not to read the commands from the .css file. Remember that the commands writen in the .html file is stronger than the command in the .css.

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

    Put the following code in your CSS file:

    table {
        font-size: inherit;
    }
    
    0 讨论(0)
  • 2020-11-22 17:36

    Regarding the concept “user agent style sheet”, consult section Cascade in the CSS 2.1 spec.

    User agent style sheets are overridden by anything that you set in your own style sheet. They are just the rock bottom: in the absence of any style sheets provided by the page or by the user, the browser still has to render the content somehow, and the user agent style sheet just describes this.

    So if you think you have a problem with a user agent style sheet, then you really have a problem with your markup, or your style sheet, or both (about which you wrote nothing).

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