• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using CSS styles

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic