• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Home
  • About
  • My Blogs
    • Photoblog
    • Knots
    • WP.com tips
kristarella.com

kristarella.com

Happiness Engineer at Automattic, lover of knitting, crochet, sci-fi and more

  • Presentations
  • Plugins
    • Exifography
  • Contact
You are here: Home / Design / Designing decisions: Cascading Style Sheets

Designing decisions: Cascading Style Sheets

3 February 2008 by kristarella

Contents
  1. Width, Padding and Margins
    1. How I thought it worked
    2. How it is supposed to work
  2. :before and :after pseudo-elements
  3. CSS inheritance
    1. What I’ve learnt about inheritance

When it comes to implementing your web designs CSS is a powerful tool. Learning CSS can be a lot of fun too.

I like to think that I’m fairly knowledgeable when it comes to CSS. It’s been fun: I started learning how to change colours and I’ve come to a point where I can lay out a whole page and figure out how to reproduce effects that I see on the net.

I knew that there were things that I didn’t know, but I didn’t realise there were so many! Most of them don’t come under the everyday use of CSS, if there is such a thing, but some do.

Width, Padding and Margins

The first, and possibly most embarrassing gap in my knowledge (not that I feel the need to be embarrassed when I don’t know something) was how padding behaves in regards to width.

How I thought it worked

I always thought that under the box model you had a box of a certain width, any padding pushes whatever was inside the box inwards and margins pushed things away from the box.

It made sense to me: if you think of it like a shipping crate or box – the box has dimensions and the padding (most likely those little styrofoam balls) go inside the box to stop the items hitting the sides of the box. This might actually be how IE works, but it’s not how standards compliant CSS is supposed to work.

How it is supposed to work

CSS Box Model

It actually works as shown above by Brett Merkey (more recent versions of IE should work the correct way).

I did discover, through practice, that my measure calculations didn’t work the way I thought they should. So, I have been using width+padding as the total dimensions — otherwise layouts just don’t work. I just thought it was buggy!

:before and :after pseudo-elements

I’ll admit that I haven’t thought much about pseudo-elements before. I’m familiar with :hover and :visited, since their use with links is a common feature of websites, but I’m not sure I’d even heard of :before and :after until recently!

I came across them because I wanted to style lists with CSS, without a background image, and using something a little more subtle than the standard bullets.

That search brought me to this W3C page (a little cumbersome to read, but useful), and A List Apart article Taming Lists.

You can use these pseudo-elements on most other elements to put an image or character(s) before or after something — a paragraph, blockquote, list, image, link… I thought that it could be useful for identifying links that open in a new window, rather than using javascript or a background image.

CSS inheritance

As described on SimpleBits,

One of the easiest ways to optimize your code when dealing with basic markup styled with CSS, is to strip out unnecessary class declarations as well as redundant div tags.

The idea is that instead of using a whole lot of ids and classes to style your page, you can cut down the clutter by using the cascade inheritance and nested elements.

<div id="post"><p class="entry"><span class="whatever">Some content.</span></p></div>
becomes,
<div id="post"><p><span>Some content.</span></p></div>
and can be styled with
#post p span {font-size:12px; color:#222;}

It saves bytes in server storage (hey, they could add up!) and it saves remembering a mass of ids and classes.

What I’ve learnt about inheritance

While I already knew about this method of implementing CSS (I think I might have even seen that SimpleBits article a few years ago. I didn’t realise that you had to be a bit careful with your specificity.

You see, when you style an element with CSS, if you give another style to the same element later in the CSS file, it overrides the earlier style. This can be useful; for example, you can set overall styles for links and then you can set more specific styles for the links within posts. Or you could remove all the default margins and paddings and add them back into each element as you like it.

However, when you’re using this inheritance method, your overriding styles must be as specific or more specific than the ones you’re trying to override.

One style might be,
#sidebar .sidebar li.widget a img {border: none;}
and I might want to give a particular image a border,
a img.framed {border: 3px solid #222;}
won’t cut it. I need to make the inheritance more specific to override the first one.
#sidebar .sidebar li.widget a img.framed {border: 3px solid #222;}

Or better yet, don’t be too specific at the start of your CSS file, and save running into problems later.
li.widget a img {border: none;}

Congratulations on getting to the end of this one!
Previous Designing decisions posts have been,

  1. Hierarchy
  2. Width
  3. Links

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on Pocket (Opens in new window) Pocket

Like this:

Like Loading...

Related

Filed Under: Design, Technology Tagged With: CSS

Reader Interactions

Comments

  1. Marco Ruelicke.net says

    4 February 2008 at 00:34

    Interesting article, though I’m not a fan of the W3C documents when it comes to looking things up. My source of wisdom when it comes to CSS or other “coding” is w3schools.com

    Maybe the CSS2 Reference shows you one or two new things you didn’t know yet 🙂

  2. kristarella says

    4 February 2008 at 09:22

    Thanks Marco.

    I find the W3C documents difficult to read, but I think they’re more useful when you don’t know anything about the topic. W3schools usually doesn’t give you as much information.

    That reference doesn’t have any ground-breaking news for me, but there are some things that I didn’t know there were so many properties for (border-style, for example). I should bookmark that page for the future.

    Cheers.

A triptych of baubles. These are very satisfying t A triptych of baubles. These are very satisfying to paint ❤️💚💙

#watercolor #watercolour #christmas
I have really enjoyed this Christmassy painting! S I have really enjoyed this Christmassy painting! So glad my friend asked me to make some cards for our church helpers, because it set me on a roll!
#watercolor #watercolour #christmas #christmascards #watercolorcards
Had a great Saturday at the GKR Karate State Title Had a great Saturday at the GKR Karate State Titles! I was a sub for @jamesxuereb.me in the Blue Flame Dragons thanks to his sprained ankle; we won first round and came fourth overall!
I did a bunch of judging and officiating, which was really good.
I didn’t place in my individual events, but had a very fun final round of kumite (sparring).

#gkrkarate #karate
More stamping tonight. Even better than last night More stamping tonight. Even better than last night’s!
Did some stamping this evening. Love it! I wish I’ Did some stamping this evening. Love it! I wish I’d done some pages in other ink colours before I dismantled the stamps 😂
Had an appointment in the city, so I got to visit Had an appointment in the city, so I got to visit the @legocertifiedstores_anz Wicked display!
#wicked #lego #afol #sydney
A little book I made from Bunnings paint sample ca A little book I made from Bunnings paint sample cards. It’s going to be for mini paintings and collages. Sometimes it’s nice to start with a colour rather than a blank white page!
A little while ago I did some swatching of Daniel A little while ago I did some swatching of Daniel Smith and Schminke Horodam watercolours. So soothing! I love some of the granulating colours!
#watercolours
Follow on Instagram

Footer

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Top Posts & Pages

  • Home
    Home
  • Rockin' the Casbar
    Rockin' the Casbar
  • Designing decisions: Cascading Style Sheets
    Designing decisions: Cascading Style Sheets
  • When you're not okay
    When you're not okay
  • Got a computer!
    Got a computer!
  • San Francisco Shopping
    San Francisco Shopping

Follow Me On…

  • Instagram
  • X
  • GitHub
  • LinkedIn
  • YouTube

Categories

Copyright © 2025 · Kristen Symonds · kristarella.com

%d