User agent stylesheet là gì

Share:

User Agent Style Sheets: Basics andSamples

Post from September 22, 2007 (↻ February 17, 2021), filed under Web Development. (Tweetthis?)This & many other posts are also available as a pretty, well-behaved ebook: On Web Development.

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

CSS takes care of the mặc định formatting of documents through the concept of user agent style sheets, a cornerstone of the cascade. It means that a website 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.


*

Figure: HTML document with Firefox defaultstyling.


Specification

CSS1 introduces the idea by stating that “each User Agent (UA, often a ‘website browser’ or ‘website client’) will have a default 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)” và 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 to 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. Unlike Microsoft’s Internet Explorer as well as Opera, for example, Gecko browsers like Firefox and Netscape Navigator (“html.css”) but also Konqueror make it rather simple lớn comprehkết thúc their default styles.

Example User Agent StyleSheets

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

For comparison, note the exemplary default style sheets proposed by the W3C in the specifications of CSS1, CSS2, CSS2.1, và CSS2.2:

User Agent và Rephối StyleSheets

The examples aim lớn 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 “phenomena.”

However, I encourage to 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, rephối style sheets are typically unnecessary. From my experience, the only occasionally helpful and then quite memorable rephối is * margin: 0; padding: 0; . Rephối style sheets are going lớn be handled in other posts though, revealing why they’re, well, bad.

About Me

*

I’m Jens Oliver aaaarrghh.com, và I’m a web developer (engineering manager) and author. I love trying things, sometimes including philosophy, art, and adventure. Here on aaaarrghh.com I cốt truyện 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 22, 2007, 12:15 CEST, Alen said:Thanks for sharing this. You said it well, it gives us better understanding of css và how/what to lớn bởi vì with our own style sheets.

Xem thêm: Code Củ Hành Lệnh 8 - Hướng Dẫn Nhận Code 3Q Củ Hành Lệnh Từ Tháng 8

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 aaaarrghh.com said:Thanks Martin—I updated the post.

On September 25, 2007, 16:29 CEST, Barney said:This is a very nice piece, Jens. I’m glad someone can give this little study authoritatively because the recent craze over remix stylesheets, & inherently the notion that browser defaults are bad, is often very misguided: If you are going 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 remix with * margin: 0; padding: 0; is the worst method of resetting the browser’s mặc định styles.Especially when working on form elements it make a lot of problems.

The better reset: Remix Reloaded

Kind regardsDaniel

On November 12, 2007, 19:50 CET, Lynne said:Interesting read… I just assumed that if the links to lớn the CSS was broken the browsers would mặc định to 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 khổng lồ find out where a textarea’s default phông (courier) comes from. Anybody?

On February 14, 2008, 22:22 CET, ty said:Thanks for an excellent writeup.So what do you start with as a mặc định then?I’ve been using a remix of sorts, & am finding some of those defining things I never use in my markup, so that seems redundant to me.How to lớn be sure borders, margins don’t create problems without resetting them or defining them 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 khổng lồ know how to lớn pry inkhổng lồ IE’s resource files to lớn view the actual UA CSS the way I can with Gecko và Webkit. Does anyone have sầu a guide on how to vày that? The googles has failed me.


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

Bài viết liên quan