FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home » CSS »  Best CSS .Classes for CSS Toolbox

Best CSS .Classes for CSS Toolbox

by Charles Torvalds 11 comments

[hide]

CSS Classes Toolbox .classAs a Professional Web Developer and Designer, CSS is by far one of the most useful tools I use. Moving from one web site to the next is made easier by having a CSS Toolbox containing some default CSS Classes that you use over and over again. Here are 10 of my favorite CSS Classes.

What are Your favorite CSS Classes? Please share your tips!

Universal CSS .Classes

Most of these are what I like to think of as "actionable" classes, IOW, they aren't just color classes or font-size classes.

  1. .S {display:block; visibility:visible;} - Shows the element.
  2. .H {display:none; visibility:hidden;} - Hides the element.
  3. .VV {visibility:visible;} - Makes the element visible.
  4. .VH {visibility:hidden;} - Hides an element but still takes up space, not fullly hidden like .H
  5. .FR {float:right;} - Floats the element to the right.
  6. .FL {float:left;} - Floats the element to the left.
  7. .DI {display:inline;} - Changes the display type to "inline".
  8. .DB {display:block;} - Makes the element a block-level element.
  9. .C {clear:both; padding:0; margin:0; line-height:2em; font-size:10px; border-bottom:1px solid #FFF;} - Clears floated elements.
  10. .CENT {margin:0 auto;} - Makes block element centred.

Please note that these classes are meant only to show what can be done with CSS, I wrote this post for CSS guru's and up and coming gurus. Sometimes I assume everyone reading my blog know as much as I do about what I'm writing about, so I skip almost all explanation and skip to the code. Basically stick to the W3C's recommendations and try not to use classes inline unless its for something specific. Most of these classes are very useful for use in javascript as well using the element.className='S' method.

Universal CSS Classes Example

<br class="C" /> - clears any block level element.
<hr class="C VH" /> - Its still a block-level element, so it correctly clears floated elements and is a semantic page separator.
 - this image will float to the right.
<p class="CENT"> - the p is centred (if width isn't 100%;).

Think you are such a CSS/semantics guru that using classes is below you? Ridiculous! Classes are extremely helpful when used properly and not in excess. Surely you don't think you know more than Eric Meyer or the W3C... please view their source code, and try to loosen up while your at it ;)


November 28th, 2007

Comments Welcome

  • http://ajaydsouza.com/ Ajay

    In addition to those above, I also use .alignleft and .alignright to align paragraph text left or right.

    I also usually create classes for different sizes of text in em

  • Luka

    I thought I've seen all with reset.css and global classes like .red or .center but this is very nice too. Thanx

  • http://www.xis.be Tom

    nice . I still need to learn a lot about css when I see this !

  • http://alexxdesign.com Alexx

    = .. much faster and less coding

  • Hostile Monkey

    Boy, you guys really didn't get Designing with Web Standards, did you?

    The Hostile Monkey hopes you eventually figure out why CSS is useful. In the meantime, best of luck with those classes!

  • http://www.invertedumbrellas.com Chad Crowell

    Nice list- I have to admit I was hoping for something more, but this is cool. I kind of do the same thing but I never keep them all in a place where I can just paste them in (maybe textexpander is a good place) - instead, I go run through old css files to find them and cut and paste...not very efficient!

  • http://css-tricks.com Chris Coyier

    .extraemphasis

    Usually strong or em tags are enough and the most appropriate semantically, but sometimes it's nice to have a universal class for adding extra emphasis to a particular element. Could be anything: a bump in font size, a border, a color change...

  • elliott cable

    This is very broken, though. The whole point of CSS is separating design from content. With these markups, you have to hardcode design decisions directly into the HTML, which is bad practice.

  • http://www.askapache.com/ AskApache

    @ Hostile Monkey

    Please don't talk about yourself in third-person on this blog. ;)

  • anonymous

    WTF. Ever hear of preserving semantics. Horrible examples. You're just going back to hardcoding values like in HTML sans CSS.

    Professional developer? Get a clue.

  • http://none Jimmy

    I think this idea is best used when editing someone else's site without having to go in an change all kinds of code. Simply drop in a new class and edit away. If I was to freelance a job, I would totally uses these classes. Make the change the client needs, quickly and they don't care how you did it.

My Online Tools

Related Articles
Twitter


My Picks
Newest Posts

WordPress Development
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain