"Easy content building for the lazy webmaster." Free content builder.

Articles are the best way to add free content to your site. There's hundreds if not thousands of article sites out there on the web that can be searched for free information.
 

RokLogin Module

Login
No account yet? Register

Syndicate

sem

Linking to an External Style Sheet PDF Print E-mail
Written by Donnie Jade   
Monday, 24 September 2007

An external style sheet may be linked to an HTML document through HTML's LINK element:

<LINK REL=StyleSheet href="style.css" TYPE="text/css" MEDIA=screen>

<LINK REL=StyleSheet href="color-8b.css" TYPE="text/css" TITLE="8-bit Color Style" MEDIA="screen, print">

<LINK REL="Alternate StyleSheet" href="color-24b.css" TYPE="text/css" TITLE="24-bit Color Style" MEDIA="screen, print">

<LINK REL=StyleSheet href="aural.css" TYPE="text/css" MEDIA=aural>

 

The <LINK> tag is placed in the document HEAD. The optional TYPE attribute is used to specify a media type--text/css for a Cascading Style Sheet--allowing browsers to ignore style sheet types that they do not support. Configuring the server to send text/css as the Content-type for CSS files is also a good idea.

External style sheets should not contain any HTML tags like <HEAD> or <STYLE>. The style sheet should consist merely of style rules or statements. A file consisting solely of

P { margin: 2em }

could be used as an external style sheet.

The <LINK> tag also takes an optional MEDIA attribute, which specifies the medium or media to which the style sheet should be applied. Possible values are

  • screen (the default value), for presentation on non-paged computer screens;
  • print, for output to a printer;
  • projection, for projected presentations;
  • aural, for speech synthesizers;
  • braille, for presentation on braille tactile feedback devices;
  • tty, for character cell displays (using a fixed-pitch font);
  • tv, for televisions;
  • all, for all output devices.

Multiple media are specified through a comma-separated list or the value all.

Netscape Navigator 4.x incorrectly ignores any linked or embedded style sheets declared with MEDIA values other than screen. For example, MEDIA="screen, projection" will cause the style sheet to be ignored by Navigator 4.x, even if the presentation device is a computer screen. Navigator 4.x also ignores style sheets declared with MEDIA=all.

The REL attribute is used to define the relationship between the linked file and the HTML document. REL=StyleSheet specifies a persistent or preferred style while REL="Alternate StyleSheet" defines an alternate style. A persistent style is one that is always applied when style sheets are enabled. The absence of the TITLE attribute, as in the first <LINK> tag in the example, defines a persistent style.

A preferred style is one that is automatically applied, such as in the second <LINK> tag in the example. The combination of REL=StyleSheet and a TITLE attribute specifies a preferred style. Authors cannot specify more than one preferred style.

An alternate style is indicated by REL="Alternate StyleSheet". The third <LINK> tag in the example defines an alternate style, which the user could choose to replace the preferred style sheet.

Note that current browsers generally lack the ability to choose alternate styles.

A single style may also be given through multiple style sheets:

<LINK REL=StyleSheet href="basics.css" TITLE="Contemporary">

<LINK REL=StyleSheet href="tables.css" TITLE="Contemporary">

<LINK REL=StyleSheet href="forms.css" TITLE="Contemporary">

In this example, three style sheets are combined into one "Contemporary" style that is applied as a preferred style sheet. To combine multiple style sheets into a single style, one must use the same TITLE with each style sheet.

An external style sheet is ideal when the style is applied to numerous pages. With an external style sheet, an author could change the look of an entire site by simply changing one file. As well, most browsers will cache an external style sheet, thus avoiding a delay in page presentation once the style sheet is cached.

Microsoft Internet Explorer 3 for Windows 95/NT4 does not support BODY background images or colors from linked style sheets. Given this bug, authors may wish to provide another mechanism for including a background image or color, such as embedding or inlining the style, or by using the BACKGROUND attribute of the BODY element.

 

Comments
Add NewSearchRSS
Roberto - alternate external resource IP:212.14.140.2 | 2008-04-08 08:42:40
Dear all, I want to provide an alternate external resource for my web community. Is it possible?
I'll try to explain better. My community http://www.qmpeople.com/ has a translated version http://www.qmpeople.fr/
Two questions:

- can I write:
Code:
[/code] ?

- can I write:
	[code]

with a 301 redirect from fr.qmpeople.com to http://www.qmpeople.fr ?

Thank you
Roberto IP:212.14.140.2 | 2008-04-08 08:43:17
Dear all, I want to provide an alternate external resource for my web community. Is it possible?
I'll try to explain better. My community http://www.qmpeople.com/ has a translated version http://www.qmpeople.fr/
Two questions:

- can I write:
Code:
link rel="alternate" hreflang="fr" type="text/html" href="http://www.qmpeople.fr/"
?

- can I write:
Code:
link rel="alternate" hreflang="fr" type="text/html" href="http://fr.qmpeople.com/"

with a 301 redirect from fr.qmpeople.com to http://www.qmpeople.fr ?

Thank you
Write comment
Name:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 

Powered by JoomlaCommentCopyright (C) 2006 Frantisek Hliva. All rights reserved.Homepage: http://cavo.co.nr/

Last Updated ( Monday, 24 September 2007 )
 

Opinion Point

I would like to see more...