School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,360 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,718 people online right now. Registration is fast and FREE... Join Now!




Including multiple stylesheets in one css file

 
Reply to this topicStart new topic

> Including multiple stylesheets in one css file, and good css files hierarchy

Rating  5
gregwhitworth
Group Icon



post 21 Mar, 2009 - 10:13 PM
Post #1


Are you tired of building css style sheets with hundreds, maybe even thousands of lines of styles? Would you like to break up the style sheet into different sections? Well here is my style sheet break down:

- Layout : This defines the structure of the website
- Fonts : Anything typography set - goes in here
- Classes : This is where all classes go (only if they are un-associated with other sections ['layout, fonts'])
- Images : All image settings go in here

This allows you to jump right into the file needed to change the element you're working on. If it's an <H1> tag, then you know to jump into the fonts.css file. This may seem obvious, but I have had to clean up multiple sites because all of the styling is in one document and not commented out.

Like all programming languages, if it isn't obvious what the style is doing - then explain it in a comment:

CODE


    /* &&&&& SETTINGS FOR APPEARING IMAGE SPANS IN GALLERY &&&&& */



So now we have 5 different (at minimum) style sheets to include in our HTML document, which would look like this:

CODE


<link type="text/css" rel="stylesheet" href="../layout.css" media="screen" />
<link type="text/css" rel="stylesheet" href="../fonts.css" media="screen" />
<link type="text/css" rel="stylesheet" href="../classes.css" media="screen" />
<link type="text/css" rel="stylesheet" href="../images.css" media="screen" />
<link type="text/css" rel="stylesheet" href="../print.css" media="print" />



As you can see - that stacks up quite a bit, and can be kind of in the way. So let's make it so that there is only two links:

CODE


<link type="text/css" rel="stylesheet" href="../all.css" media="screen" />
<link type="text/css" rel="stylesheet" href="../print.css" media="print" />



Now you have only 2 linked style sheets, but what happened to all of our styles then - well we create an 'all.css' file that links to all of the other ones. This allows you to continue your cascading without having to place includes at the very bottom of css files (which can be hundreds of lines long).

SO tell me how to include already! Put this in your all.css file

CODE


@import 'layout.css';
@import 'fonts.css';
@import 'images.css';
@import 'classes.css';



This is a great setup, especially if you have many people working on the site. Hope this helps.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 07:49PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month