Page 1 of 1
Best way to include CSS files
Posted: Sun Jul 28, 2002 2:23 pm
by RandomEngy
I was wondering what the best way to include a CSS file is. You could use the link function for a clientside include or just put the whole declaration in a file, and include it via PHP inside the <head> tags. Which way is better, or does it not matter?
Posted: Sun Jul 28, 2002 2:45 pm
by protokol
well if you have more than one script using the css file, then do the client side link ... that way the css only gets parsed 1 time instead of each time a script which has it inline is called
Posted: Sun Jul 28, 2002 4:06 pm
by kaizix
also, if it's linked instead of the whole thing in each file, it makes it easier to update or change (since all the files use one file and you can just change that file)
Posted: Sun Jul 28, 2002 4:53 pm
by daemorhedron
kaizix wrote:also, if it's linked instead of the whole thing in each file, it makes it easier to update or change (since all the files use one file and you can just change that file)
Exactly. My vote goes for a <link> tag too.
Posted: Sun Jul 28, 2002 6:03 pm
by craginweb
I always link my style sheets to make things easier when changing the look of the site.
Just put the following code in your header file.
Code: Select all
<?php
echo "<link rel="stylesheet" href="your_style.css" type="text/css" />";
?>
Posted: Mon Jul 29, 2002 9:07 am
by RandomEngy
I will use the link tag because of what protokol said, but to be fair, you would have to just edit one file for using the PHP include as well.
Posted: Mon Jul 29, 2002 10:02 am
by RandomEngy
Errr... hmm... okay, it doesn't seem to be including correctly that way.
Inside head:
Code: Select all
<link rel="stylesheet" href="include.css" type="text/css" />
include.css (in same folder):
Code: Select all
<style type="text/css">
body {font-family: Arial, sans-serif; background-color: #FFFFFF; color: #000000}
A:link {color: #0000FF}
A:visited {color: #000066}
A:active {color: #3366FF}
A:hover {color: #0099FF}
</style>
The link colors work fine but none of the body modifiers work when I include the file via <link>.
Posted: Mon Jul 29, 2002 10:22 am
by twigletmac
Try changing:
Code: Select all
<style type="text/css">
body {font-family: Arial, sans-serif; background-color: #FFFFFF; color: #000000}
A:link {color: #0000FF}
A:visited {color: #000066}
A:active {color: #3366FF}
A:hover {color: #0099FF}
</style>
to
Code: Select all
body {
font-family: Arial, sans-serif;
background-color: #FFFFFF;
color: #000000;
}
A:link {color: #0000FF;}
A:visited {color: #000066;}
A:active {color: #3366FF;}
A:hover {color: #0099FF;}
You don't need the style tags because you're already in a document which has been defined as a style sheet.
Mac
Posted: Mon Jul 29, 2002 11:39 am
by RandomEngy
Ahh, works perfectly now. Don't know what this board would do without you mac. :D