File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using CSS styles

 
Jay Damon
Ranch Hand
Posts: 282
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Four questions:

1. I am working on an application that currently has some 30+ CSS files. I maintain that this is just wrong and defeats the purpose of using CSS files in the first place. Sites I have previously worked at usually had just one CSS file or at least only a few. What is considered correct? Is there any definitive place on the web that addresses this?

2. What is considered the best way to handle styles that are unique to a page, e.g. to create proper spacing? My preference would be to create an embedded style sheet, i.e. within an HTML element.

3. Is there ever a valid use for inline styles other than to quickly mock up an HTML page or handle something that is truly unique?

4. Is it considered better to use a single style class name, i.e. class="mystyle", or use multiple style class names, i.e. class="my style", for HTML elements? It seems to me that multiple class names would enable greater reuse of styles.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will give you some tips: http://erraticwisdom.com/2006/01/18/5-tips-for-organizing-your-css

You really should have one CSS that all of the pages use. You need to make generic css rules that apply to the pages. It makes it easier to update things. Some people tend to have the same rule named differently on pages because they are too lazy to see if something is already like that.

If you find that rules are to specific, break them up into smaller chunks and combine them in the CSS tag.

You can use inline, but it defeats the purpose of easily updating stuff in the future. Feel free to give that find and replace feature a reson to exist still!

Also read through the pages here: http://www.nypl.org/styleguide/css/index.html

Eric
 
Jay Damon
Ranch Hand
Posts: 282
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric.

When you say combine them, you mean in the element class attribute, right?


If you find that rules are to specific, break them up into smaller chunks and combine them in the CSS tag.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meant class attribute

class="rule1 rule2"

or you could do
combinations in the riles

.rule1, .rule2, .rule3{
color: red;
}

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll disagree a bit on the "one file" rule.

One of the apps I work on is large fincanical application with tons of pages. While all pages do include a large "core" stylesheet that defines styles that should be maintained throughout the site, we also have a handful of smaller styles sheets that are only applicable to particular categories of pages. For example, pages that emulate dialog boxes have a css file that augments the "core" set of styles with dialog-only style elements.

But even in this enormous app we only have about a dozen different style sheet files that are logically broken up as described above. 30+ does sound excessive.
[ March 15, 2006: Message edited by: Bear Bibeault ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic