Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer: Jan Roland Eriksson ciwas stylesheet authoring FAQ v1.16 ______________________________________________________________________ The Purpose, Scope and Notation of this FAQ-list. This FAQ-list contains the edited result of a collective effort among regular participants in the Usenet newsgroup... comp.infosystems.www.authoring.stylesheets The purpose of this document is to provide answers to a few of the most frequent questions raised in the 'ciwas' Usenet newsgroup. At the moment, almost all discussion on this group relates to CSS, although that might not always be so. This document does not aim to be a complete tutorial in stylesheets or in CSS. There is a separate FAQ-list about the Usenet group itself, its charter, customs and posting conventions. For further information about stylesheets and about CSS see the resources listed in the resource sections of http://css.nu/faq/ciwas-mFAQ.html The following notational convention is used in this FAQ. Single quote marks are used to denote keywords, e.g. 'font-family' and those quote marks are not a part of the keyword. Double quote marks are used to denote text that is quoted from another source, and/or to mark jargon. e.g. "Generic font family names are keywords..." would indicate that the line contains quoted material. Stars denote emphasized text... e.g. *not* would put emphasis on the word "not". ______________________________________________________________________ 00: ===== T O C ===== 01: I want my page fonts to look the same every where as in... a) Why are my font sizes different in different browsers ? b) Why are my font sizes different on different platforms ? 02: Why shouldn't I use fixed sized fonts ? 03: Which font names are available on all platforms ? 04: How can I make a page look the same in e.g. NS and MSIE ? 05: Why is my external stylesheet not working ? 06: Why does Netscape lose my styles ? 07: How does a simple CSS style rule look ? 08: How can I suggest a different link appearance in various sections of my page ? 09: Why is it my ':hover' declaration for links does not work ? 10: Where can I learn more about CSS ? 11: How can I check my CSS creations and find out about errors ? 12: What is this thing I hear about ..., in your external stylesheets. CSS comments are defined as anything that is placed between /* (the comment start mark) and */ (the comment end mark). I.e. as follows... /* This text right here is a correct CSS comment */ CSS comments may span multiple lines in the stylesheet. Nesting of CSS comments is *not* allowed. Another reason for external stylesheets (and even embedded and inline stylerules) not to function as expected may be that you have tried to make use of some CSS-features that are not supported in the browser you are using. Browser support for CSS varies and a good place to find out more about what is or is not supported is "The Mastergrid"... http://www.webreview.com/style/css1/charts/mastergrid.shtml External stylesheets shall also be served from the www-server with a MIME-type of 'text/css' in its 'Content Type:' HTTP header. You may need to negotiate with your server admin to add this MIME type to your server if you are not able to configure the server yourself. Registered MIME types can be found in the IANA repository... ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/ RFC2318 describes the specific 'text/css' MIME type. http://www.ietf.org/rfc/rfc2318.txt HTTP header content for www resources may be checked here... http://www.rexswain.com/httpview.html http://www.delorie.com/web/headers.html http://www.webmastermatrix.com/webtools/HTTP%20Header%20Viewer.htm 06: ===== Q & A ===== Q: Why does Netscape lose my styles ? A: Netscape 4.x has poor support for CSS. Having said that, the following points should be noted. Invalid HTML will almost certainly cause Netscape to ignore your CSS suggestions at some point. You will find that valid HTML is your best friend, but for Netscape to work properly you must ensure that *all* elements in your markup which permit closing tags are explicitly closed. Check and correct your CSS suggestions for the very same reason, Netscape 4.x is in fact doing "the right thing", as per CSS specs (as opposed to MSIE) when it ignores style rules with errors. Netscape 4.x has what's called an "inheritance problem" into its TABLE element. It can be argued that NS is all within its right to behave as it does in this case, but since the workaround is quite simple it's easy enough to just use it and be done with it. Let's say you want your TABLE content to "look the same" as your BODY content? "Redundant" styling comes to your help as in e.g. BODY, TABLE, TH, TD { /* insert your styles here */ } On a generic level, Netscape 4.x likes to have style rules applied directly to the elements where they are needed. You can never really trust the inheritance principle to work correctly at any level in Netscape 4.x. See... http://css.nu/pointers/bugs.html for more details of bugs and workarounds in Netscape's CSS support. A good method to limit the influence of CSS in the Netscape 4.x family of browsers is to make use of the '@import' trick to serve only such levels of CSS to Netscape 4.x that it can cope with. Johannes Koch describes svereal methods that can be used to isolate certain browsers from CSS rules that are supported less than good... http://pixels.pixelpark.com/~koch/hide_css_from_browsers/ 07: ===== Q & A ===== Q: How does a simple CSS style rule look ? A: P { font-family: serif; font-size: 1.2em; } Here we see a rule with a 'selector' P that has been given two style declarations, i.e. two 'property:value' pairs. 'font-family' and 'font-size' are properties of the content of element P, and these properties are assigned the values of 'serif' and '1.2em' respectively. A colon ':' is the *value assignment symbol* in CSS, so using an equal sign '=' instead is an *error* and is required by the CSS specification to be ignored. Any browser that appears to honor this style is behaving improperly. For length values a 'unit' is always needed and there shall *never* be any space between a number and its length unit. A value given as e.g. '1.2 em' is an *error* and is required by the CSS specification to be ignored. Any browser that appears to honor this style is behaving improperly. A semicolon ';' *between* declarations is required but it's also good "rule of thumb" to put a ';' even after the last declaration. Finally, curly braces '{...}' group one or more declarations into a final CSS rule. For more details on the basics of CSS style rules, see Section 1 "Basic concepts" in the CSS1 specification... http://www.w3.org/TR/REC-CSS1#basic-concepts 08: ===== Q & A ===== Q: How can I suggest a different link appearance in various sections of my page ? A: The most direct approach is to define separate classes for your link types and then use those classes directly in your Link to Foo Link to Bar ...to suggest a difference in appearance for what could be your internal or external links. Most CSS properties are available for setting up style rules for links and the example above is kept to a minimum only to save space. Also note that the grammatic rules for CSS1 only allows for this following link selector format to be used... a.internal:link { background: #c0c0c0; color: #800080; } ...while the grammar for CSS2 allows for both of these... a.internal:link { background: #c0c0c0; color: #800080; } a:link.internal { background: #c0c0c0; color: #800080; } Since support for the CSS1 syntax is more wide spread, it is advised that you only use CSS1 syntax for your link style rules. 09: ===== Q & A ===== Q: Why is it my ':hover' declaration for links does not work ? A: Assuming you have already checked that your style sheet declarations do conform to correct CSS syntax, it could be that you have overlooked the importance of a correct order of style declarations for links. The CSS2 specification makes this following note on the importance of placing the dynamic pseudo-classes ':hover' and ':active' in correct positions in a list of style declarations. "Note that the 'a:hover' must be placed after the 'a:link' and 'a:visited' rules, since otherwise the cascading rules will hide the 'color' property of the 'a:hover' rule. Similarly, because 'a:active' is placed after 'a:hover', the active color will apply when the user both activates and hovers over the 'a' element." See also Q & A - 08: above for an example of correct ordering of link style declarations, and further, for the full theory, see these parts of the CSS2 spec. http://www.w3.org/TR/REC-CSS2/selector.html#link-pseudo-classes http://www.w3.org/TR/REC-CSS2/selector.html#dynamic-pseudo-classes Note that the ':hover' pseudo-class entered into CSS specs in CSS2. Browsers that do not claim to support CSS2 at any level, can not be expected to support the ':hover' pseudo-class. E.g. Netscape 4.x and Opera 3.x browsers does not have support for the ':hover' pseudo-class. 10: ===== Q & A ===== Q: Where can I learn more about CSS ? A: The meta-FAQ for comp.infosystems.www.authoring.stylesheets has a resource section that lists a large number of URL's to www-sites that are know to contain good information on how to use and author Cascading Style Sheets (i.e. CSS for short). The meta-FAQ is posted here in this NG with the same frequency as this FAQ, but can also be found on the www as an HTML document. http://css.nu/faq/ciwas-mFAQ.html ...or as a plain text document... http://css.nu/faq/ciwas-mFAQ.txt 11: ===== Q & A ===== Q: How can I check my CSS creations and find out about errors ? A: For traditional markup syntax validation... http://www.htmlhelp.org/tools/validator/ http://valet.webthing.com/page/ http://validator.w3.org/ For CSS check-ups... http://www.htmlhelp.org/tools/csscheck/ http://jigsaw.w3.org/css-validator/validator.html.en Make friends with the URL's above, they *will* save you a lot of time and frustration. To emphasize this point, *overly* correct HTML markup -- I.e. explicitly closing elements which do not strictly require this -- and correct use of CSS, is essential to ensure properly rendered CSS on the www. The validator located at webthing.com (The Page Valet, URL above) has an experimental "normalised markup" option that makes use of "spam" (SPAddMarkup) to insert, among other things, the optional closing tags. "The Page Valet" is based on exactly the same code and error messages as is used for the validator at htmlhelp.org "To err is human", but for once there is something that computers can help out with: *error checking*. Just like spell checkers may catch irritating typos that are so hard to spot by eye, HTML validators and CSS checkers are available on-line to check your web pages (URL's above). You will need to use your knowledge of HTML and CSS to interpret the results of these tools, but you can post follow-up questions to this NG, comp.infosystems.www.authoring.stylesheets for further discussion. 12: ===== Q & A ===== Q: What is this thing I hear about For XHTML 1.0 this following declaration should be safe in your prologue for the purpose of suggesting a "strict" rendering mode. For additional information on the full span of variations that came as a result of the introduction of " .... with somewhere in the document. Direct adressability by scripts: document.getElementById('bar').firstchild.nodeValue = 'Hello world!'; There's also a difference between CLASS and ID attributes as regards to the allowable format of values. By HTML rules, CLASS is CDATA, which basically means 'anything goes', but CSS rules impose some restrictions. And by HTML rules, ID is ID, which means that only letters of the English alphabet ([A-Za-z]), digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".") are permitted, and the first character must be a letter (and underscores don't work reliably) 16: ===== E N D =====