Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including css

Status
Not open for further replies.

ice78991

Programmer
Nov 20, 2006
216
Does it make any difference if I put my css directly into my page or whether I use
Code:
<link rel="stylesheet" href="styles.css" type="text/css" />
Assuming the styles are used in this page only, which is the preferred method
 
Linking is always preferred for two reasons:

1. It keeps the page weight down, as the file will be cached initally, and

2. People with no CSS support aren't forced to download code of no use to them.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I'd add number 3,

3. It makes code maintenance much easier as you only have 1 place to edit

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Foamcow said:
3. It makes code maintenance much easier as you only have 1 place to edit
You haven't seen the css files for the project I'm working on [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Does it follow then that it is ok to put all of your css (or javascript - I assume .js works the same) into 1 page - ie it is not necesary to try to break up your css into smaller files for each page
 
I say this because having all css in 1 place would make organization easier for my project and I would be taking advantage of file caching (I accept the first page may be a little slower to load when the initial cache takes place but hopefully not by a great deal)
 
Not necessarily. For example, you might split out navigation into one CSS and JS file, and layout into another.

The advantage of this is that if your navigation never changes but your layout does, browsers will still load the cached nav file but fetch down the updated layout file.

As you can see, it really depends on how often certain parts of your site change.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I tend to create a stylesheet with base styles then additional sheets for different pages if I need them.

Most commonly I have something like

global.css <- base styles
home.css <- the home page tends to have a different layout
inner.css <- inner pages
forms.css <- form elements

I may also have one for the nav, but normally this goes in the global stylesheet.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Oh yes - we normally have IE6- and IE7-specific override CSS files, as well as a printer CSS file. You can link these in by specifying a media type (for the printer CSS file), and using IE-only conditional comments.

You can find out more about the latter in faq215-6625. Printer style sheets are linked in as follows:

Code:
<link rel="stylesheet" href="/assets/css/print.css" type="text/css" [!]media="print"[/!]>

I can't think of much else you'd need CSS-wise :)

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top