About

Thoughts on Design is a blog on web design and front-end coding. Served up monthly-ish by Jamis Charles.

Search

Categories

Posts Tagged ‘CSS’

How to write a CSS rule that will affect every element:


25 of October2007

Sometimes there’s a need to reset all of the margins on a page, or you simply want something specifically applied to each element without having to count on inheritances to do the job. The solution: “*” or “universal selector”. This seems familiar from other languages right? Well, it should be. It simply means “everything” in a selected area.

The following will apply a gray background to every element on a page.

* {
    background-color: #eee;
}

What if you want to get more specific?
With this code, everything within the div with the id=”wrapper” will have a gray background.

div#wrapper * {
    background-color: #eee;
}

Obviously any properties can be used here. Enjoy.