Scott Bush

Like Facebook, but with far fewer readers.
  • rss
  • Home
  • Portfolio
    • Education
    • Career
    • Volunteer
  • About Me

Little-known CSS selectors

22 January 2007

CSS iconAnyone worth his or her proverbial web development salt knows cascading style sheets (CSS) are the way to go to style content (and construct layouts, enable views for alternate medias, etc.). CSS employs “selectors” to target specific entitities in X/HTML, which can then be manipulated. (I’m glossing this over, of course; read any of the sites in my blogroll or Google CSS to dive into the ocean of CSS information.) Most people’s CSS use is limited the “big three” basic selectors:

  1. Overriding HTML elements - Want to change the font for headings or the color of your page’s background? Add CSS rules for H1, H2, Hn and BODY.
  2. Classes - Looking to group particular elements so they can be styled the same? Use a class selector, like .menu (note that period preceeding the class name, it’s important!).
  3. IDs - Need to target a unique element, such as a footer or sidebar? IDs provide the means to do so. You’ll use a pound sign to select an ID in your CSS, like this: #footer.

Using these three alone get you pretty far, though CSS provides a number of more specific selectors wielded by the true CSS wizards.
The other day I was styling a simple log-in form for my organization’s wireless network. I’d increased the size of the username and password fields by overriding the INPUT element:

input {
font-size: 1.5em;
color: #006B0C;
margin: .25em .75em 0em 0em;
}

Unfortunately, the above rule also ballooned my form’s submit button, which was ugly. I knew there had to be a way to target a form’s button in CSS… and I found it:
input[type="submit"] { font-size: 1.0em; }
Note the bracket syntax above. It targets an element’s attributes, which was exactly what I needed for my form. I wanted big INPUTs, except when that input is a submit button (type="submit"). The same selector could be used to target links whose rel attribute is external, say.

Categories
Web Dev
Comments rss
Comments rss
Trackback
Trackback

« Boringly Ever After iPress for the iPhone »

One response

Very nice find! I've wondered about that before! Sean.

sean | 22 January 2007 | 10:56 am

Very nice find! I’ve wondered about that before!

Sean.

Leave a comment

You must be logged in to post a comment


Recent Posts

  • 2008 Wrap-Up
  • Why buttons are still relevant on iPods
  • Design of a Holiday Letter
  • Just because it snows doesn’t mean you can be crazy
  • Is this the best or worst PPC ad?

Now Reading...

Planned books:

None

Current books:

  • 20,000 Leagues Under the Sea (Unabridged Classics)

    20,000 Leagues Under the Sea (Unabridged Classics) by Jules Verne

Recent books:

  • Utopia (Penguin Classics) by Thomas More
  • Aikido in Everyday Life: Giving In to Get Your Way Second Edition by Terry Dobson
  • Faust: Part One (Oxford World’s Classic) by Johann Wolfgang von Goethe
  • His Dark Materials Omnibus (The Golden Compass; The Subtle Knife; The Amber Spyglass) by Philip Pullman
  • The Way of Sanchin Kata: The Application of Power by Kris Wilder

View full Library

Blogroll

  • Colby Creative
  • Crystal and Scott
  • Eric Nusser’s “I got the broken cookie” blog
  • Margielize and Jacob’s blog
  • Sean Neumann

Webdev/UI

  • 456 Berea Street
  • A List Apart
  • Digital Web Magazine
  • Nourishment to help the web grow
  • Smashing Magazine
  • UseIt.com
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox