This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Using CSS styles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using CSS styles" Watch "Using CSS styles" New topic
Author

Using CSS styles

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 31, 2001
Posts: 282
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using CSS styles
 
Similar Threads
Writing RTF files from Java Swing DefaultStyledDocuments
Java Data Structure for HTML Class Selectors and CSS style Sheet?
Automatically extract styles into CSS?
what is the use of class attribute associated with a HTML element.
HTML in JSP tag