User Agent Stylesheet Là Gì

User Agent Style Sheets: Basics andSamples

Post from September 22, 2007 (↻ February 17, 2021), filed under Web Development. (Tweetthis?)This and many other posts are also available as a pretty, well-behaved ebook: On Web Development.Bạn đã xem: User agent stylesheet là gì

CSS takes care of the default formatting of documents through the concept of user agent style sheets, a cornerstone of the cascade. It means that a web browser doesn’t just present a line of text when it’s fed with an HTML document that has no styling information attached, but instead serves it using minimal formatting.

Bạn đang xem: User agent stylesheet là gì


*

Figure: HTML document with Firefox defaultstyling.

Specification

CSS1 introduces the idea by stating that “each User Agent (UA, often a ‘website browser’ or ‘web client’) will have sầu a mặc định style sheet that presents documents in a reasonable—but arguably mundane—manner.” CSS2 says that “conforming user agents must apply a mặc định style sheet (or behave sầu as if they did)” & that “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.” CSS3 is of the same mind.

Since the CSS specifications leave sầu it up to implementations whether khổng lồ use a “real” style sheet for default display or not, it’s not surprising that you don’t find a default style sheet in every browser’s installation folder. Unlượt thích Microsoft’s Internet Explorer as well as Opera, for example, Gecko browsers lượt thích Firefox và Netscape Navigator (“html.css”) but also Konqueror make it rather simple to comprehend their mặc định styles.

Example User Agent StyleSheets

The following is a list of mặc định style sheets I’ve sầu compiled over recent years (except for Safari; thank you, Martin). Due to lớn the fact that Firebird, Firefox, and Co. are all based on the same layout engine, they’re quite similar, if not identical.

For comparison, note the exemplary mặc định style sheets proposed by the W3C in the specifications of CSS1, CSS2, CSS2.1, và CSS2.2:

User Agent & Remix StyleSheets

The examples ayên to provide some insight inkhổng lồ user agent style sheets. Knowledge of user agent style sheets should help get a better understanding of CSS as well as any display “phenomemãng cầu.”

However, I encourage khổng lồ use this knowledge for other things than building more or larger “reset” style sheets. Assuming use of additional style sheets other than just a rephối, reset style sheets are typically unnecessary. From my experience, the only occasionally helpful & then quite memorable rephối is * margin: 0; padding: 0; . Remix style sheets are going to be handled in other posts though, revealing why they’re, well, bad.

About Me


*

I’m Jens Oliver phung123.com, & I’m a web developer (engineering manager) and author. I love sầu trying things, sometimes including philosophy, art, and adventure. Here on phung123.com I chia sẻ some of my views andexperiences.If you have questions or suggestions about what I write, please leave sầu a bình luận (if available) or amessage.

Comments (Closed)

On September 24, 2007, 8:37 CEST, Martin Hassman said:For Safari/Webkit stylesheets cannot be found in the installation (propably compiled into some library), but they are on the web source tracking system with their history

html4.cssquirks.css

On September 24, 2007, 11:18 CEST, Jens Oliver phung123.com said:Thanks Martin—I updated the post.

Xem thêm: Next Free Download War Chess Full Version Pc Games War Chess 3D Full Version

On September 25, 2007, 16:29 CEST, Barney said:This is a very nice piece, Jens. I’m glad someone can give sầu this little study authoritatively because the recent craze over rephối stylesheets, và inherently the notion that browser defaults are bad, is often very misguided: If you are going to lớn respecify everything, there is no need for the extra rule for every element; if you aren’t, you’re far better off with the user/developer’s consideration than nothing.

On September 26, 2007, 9:54 CEST, Daniel said:I absolutely don’t agree with you. The rephối with * margin: 0; padding: 0; is the worst method of resetting the browser’s mặc định styles.Especially when working on khung elements it make a lot of problems.

The better reset: Rephối Reloaded

Kind regardsDaniel

On November 12, 2007, 19:50 CET, Lynne said:Interesting read… I just assumed that if the liên kết lớn the CSS was broken the browsers would mặc định khổng lồ plain HTML formatting. However, it certainly makes more sense lớn have sầu a default css tệp tin.

On December 30, 2007, 23:34 CET, Lazar said:Thanks for this. It’s really useful info! Especially for CSS beginners lượt thích me.

On January 7, 2008, 15:53 CET, Anders said:Interesting read, but I am not able to lớn find out where a textarea’s default font (courier) comes from. Anybody?

On February 14, 2008, 22:22 CET, ty said:Thanks for an excellent writeup.So what vị you start with as a default then?I’ve sầu been using a rephối of sorts, và am finding some of those defining things I never use in my markup, so that seems redundant to lớn me.How to be sure borders, margins don’t create problems without resetting them or defining them to lớn be the same despite whatever UA styling could derail a layout?

On April 28, 2011, 20:37 CEST, John Lascurettes said:I would love to know how to pry into lớn IE’s resource files lớn view the actual UA CSS the way I can with Gecko & Webkit. Does anyone have sầu a guide on how to lớn vị that? The googles has failed me.


*

Perhaps my most relevant book: CSS Optimization Basics (2018). Writing CSS is a craft. As craftspeople we strive to lớn write high quality CSS. In CSS Optimization Basics I lay out some of the most important aspects of such CSS. Available at Amazon, Google Play Books, andLeanpub.

Leave a Reply

Your email address will not be published. Required fields are marked *