linking to a stylesheet in xhtml

  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Hey,
I'm trying to convert my site to xhtml and I have everything working fine ... except for the stylesheet. I'm rather confused. Help?

Here are the first three lines of code (in case it has something to do with it:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

Neither of these work:

<link href="site.css" media="screen" type="text/css" />

<?xml-stylesheet href="site.css type="text/css" />

- The Maven
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Chances are your style sheet code is something similar to this:

Code: [ Select ]
<link rel="stylesheet" type="text/css" href="resume.css">


That's normal for HTML 4.01, but you need to add a forward slash at the end for XHTML like this:

Code: [ Select ]
<link rel="stylesheet" type="text/css" href="stylesheet.css" />


If that doesn't work, make sure that the link is correct and the stylesheet is where it is supposed to be. Also, notice how all the elements are small case for XHTML. With HTML 4.01 it doesn't matter, but with XHTML all elements and attributes need to be small case.

---------looks like you edited your post--------
OK then try this:
Code: [ Select ]
<link rel="stylesheet" type="text/css" href="site.css" />


It should work.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Just noticed in your code...you have this:

Code: [ Select ]
<?xml-stylesheet href="site.css type="text/css" />


I've never tried it that way, so would have no idea if it would work anyway, but you are missing a closing quotation mark after site.css. XHTML is very particular about closing quotation marks.

Also, technically your doctype declaration should be:

Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


I also think if you are going to include XML in the document, you need to include this prior to the doctype:

Code: [ Select ]
<?xml version="1.0" encoding="iso-8859-1" ?>
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Thanks, I'll have to try that. :D
- The Maven
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5146
  • Loc: SC-USA

Post 3+ Months Ago

If you're writing for older browsers you can also do this:
Code: [ Select ]
<link rel="stylesheet" type="text/css" href="style for old browsers.css" />
<style>@import url("style for new browsers.css");</style>
  1. <link rel="stylesheet" type="text/css" href="style for old browsers.css" />
  2. <style>@import url("style for new browsers.css");</style>

older browsers, like NS 4.x, will only read the LINK tag. Newer browsers, however, will read both tags and give preference to the document referenced in the @import declaration.
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Thanks digitalMedia,

the @import url method worked for me. I really appreciate that.

- The Maven
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23458
  • Loc: Woodbridge VA

Post 3+ Months Ago

Yep...nice tip dM. I love it when a family comes together!

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 22 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.