Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition)

Q&A

Q1:

Say I link a style sheet to my page that says all text should be blue, but there's a <span > tag in the page somewhere. Will that text come out blue or red?

A1:

Red. Local inline styles always take precedence over external style sheets. Any style specifications you put between <style> and </style> tags at the top of a page will also take precedence over external style sheets (but not over inline styles later in the same page). This is the cascading effect of style sheets that I mentioned earlier in the hour. So you can think of cascading style effects as starting with an external style sheet, which is overridden by an internal style sheet, which is overridden by inline styles.

Q2:

Can I link more than one style sheet to a single page?

A2:

Sure. For example, you might have a sheet for font stuff and another one for margins and spacingjust include a <link /> for both. Technically speaking, the CSS standard requires web browsers to give the user the option to choose between style sheets when multiple sheets are presented via multiple <link /> tags. However, in practice all major web browsers simply include every style sheet. The preferred technique for linking in multiple style sheets involves using the special @import command. Following is an example of importing multiple style sheets with @import:

@import url(styles1.css); @import url(styles2.css);

Similar to the <link /> tag, the @import command must be placed in the head of a web page. You learn more about this handy little command in Hour 15, "Creating Print-Friendly Web Pages," when you find out how to create a style sheet specifically for printing web pages.

Категории