Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Using the <link> Element

October 30, 2000

The second mechanism for associating style sheets with media types is to use the elements media attribute, which specifies the intended destination media for the external style information. This allows user agents to load and apply external style sheets based on the characteristics of the media where the document is being rendered.

For example, if you write:

<HEAD>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="print" HREF="myprint.css"/>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="screen" HREF="myscrn.css"/>
</HEAD>
[Note: The 2nd and 3rd lines above are one line, as is the 4th and 5th. They were split for formatting purposes]

you are indicating that the myprint.css style sheet should be used when printing the document, and that the myscrn.css style sheet should be used when displaying the document.

At the time that this book was written, only Microsoft Internet Explorer properly supported the <link> element with media types. With Netscape Navigator, if you specify anything other than the screen media type, Navigator will ignore the entire element, and therefore ignore the entire external style sheet!

Try It Out — Using the <link> Element to Handle Different Media Types

In this exercise, we will use two external style sheets to control the display and printing.

Type the following into your text editor:

body { font-size: 18pt }
span.speaker { background-color: yellow }
.stage { font-style: italic }
p.stage { text-align: center }
Save the file as linkscrn.css

Create a new document in your text editor and type the following:

body { font-size: 10pt }
span.speaker { font-weight: bold }
.stage { font-style: italic }
p.stage { text-align: center }
Save this file as linkprnt.css

Edit the file style1.htm and make the following changes to the <head> section:

<HEAD>
<TITLE>Tempest Links</TITLE>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="print" HREF="linkprnt.css"/>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="screen" HREF="linkscrn.css"/>
</HEAD>
[Note: The 3rd and 4th lines above are one line, as is the 5th and 6th. They were split for formatting purposes]

Save the file as link.htm and run it in Microsoft Internet Explorer. You should see something like: Example 5
From within your browser, select the File | Print menu item. You should see something like: Example 6
How It Works

We simply took our two style sheets out of the document and put them into separate documents of their own. Note that the content of the style sheets wasn't changed in any way, so that what is seen on the browser and the printed page are identical to those of the last example. In the <head> of the document, we simply associate these external style sheets with the document content like so:

<HEAD>
<TITLE>Tempest</TITLE>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="print" HREF="linkprnt.css"/>
<LINK REL="stylesheet" TYPE="text/css"
		MEDIA="screen" HREF="linkscrn.css"/>
</HEAD>
[Note: The 3rd and 4th lines above are one line, as is the 5th and 6th. They were split for formatting purposes]

We can see that there are two <link> elements. The first identifies the style sheet to use for the print media type and the second identifies the style sheet to use for the screen media type. The files were the style information is contained is given as the value of the href attribute.

When we looked at our document in the web browser, the style sheet corresponding to the screen media type was opened and used. When we sent our document to the printer, the style sheet corresponding to the print media type was opened and used instead.

Application of the Different Styles
Beginning XHTML
Using the '@media' Rules


Up to => Home / Authoring / Languages / XML / BeginningXHTML




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers