Best way to include CSS files

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Best way to include CSS files

Post 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?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post 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)
daemorhedron
Forum Commoner
Posts: 52
Joined: Tue Jul 23, 2002 11:03 am

Post 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.
craginweb
Forum Newbie
Posts: 13
Joined: Fri Jul 05, 2002 12:49 am
Location: FWB Florida

Post 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" />";
?>
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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.
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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 &#123;font-family: Arial, sans-serif; background-color: #FFFFFF; color: #000000&#125;
A:link &#123;color: #0000FF&#125;
A:visited &#123;color: #000066&#125;
A:active &#123;color: #3366FF&#125;
A:hover &#123;color: #0099FF&#125;
</style>
The link colors work fine but none of the body modifiers work when I include the file via <link>.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try changing:

Code: Select all

<style type="text/css"> 
body &#123;font-family: Arial, sans-serif; background-color: #FFFFFF; color: #000000&#125; 
A:link &#123;color: #0000FF&#125; 
A:visited &#123;color: #000066&#125; 
A:active &#123;color: #3366FF&#125; 
A:hover &#123;color: #0099FF&#125; 
</style>
to

Code: Select all

body &#123;
    font-family: Arial, sans-serif;
    background-color: #FFFFFF;
    color: #000000;
&#125; 
A:link &#123;color: #0000FF;&#125; 
A:visited &#123;color: #000066;&#125; 
A:active &#123;color: #3366FF;&#125; 
A:hover &#123;color: #0099FF;&#125;
You don't need the style tags because you're already in a document which has been defined as a style sheet.

Mac
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Ahh, works perfectly now. Don't know what this board would do without you mac. :D
Post Reply