Let's start adding style.
There are hundreds and hundreds of different properties at our disposal to change the look and feel of our web pages. In this section we'll start at the beginning and introduce some of the more basic properties to get you started. From there, future sections will build upon this.
I don't believe it would be productive for us to go through every single property available to you. Instead, what I am going to do is introduce you to some of the more frequently used properties to give you a feel for how they work. Once you are comfortable with them, picking up new ones is not that difficult. We'll start with CSS properties at CSS Level 1. CSS Levels 2 and 3 mostly just introduce new properties (some of them are a bit tricky to understand the intricacies of but as your skill with CSS grow they won't be that scary).
The official CSS Level 1 standard may be found here:
If you scroll down a bit on the document you will see they have provided a nice table of contents. Properties start from item 5. Most of the properties are named so that you can easily understand what they do. This makes it easy to find the properties you need. If you click on a property it will give you the full outline of it. This includes:
There are other things that will be listed but these will be the most useful to you.
I wouldn't try to remember all the properties but instead keep this document open when you are writing your code so you can easily refer back to it.
In the rest of this section we'll demonstrate CSS properties. We will apply them all to the following HTML.
Here is a small sample of things you can change with text.
The font-family property allows us to change the particular font we are using. You may select any font which is installed on the clients computer with this property. Some of the more commonly used fonts include:
It is possible to specify and include non standard fonts but this is a little more complex. We'll look at this later.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
Font-size may be specified using a few different types but the easiest to work with is pixels (px).
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
The font-weight css property allows us to specify how thick the lines of the characters are. It may be one of the following values:
Some font families only have normal and bold weights. In this case if you specify lighter it will default back to normal and if you specify bolder it will default back to bold.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
Colour is a reasonably complex thing to define. There are several ways in which we can do this. We will look at colour in much more detail in a later section. Here we will just work with it in it's simplest form which is with Hexadecimal numbers. A colour is specified by a hash ( # ) followed by 6 hexadeximal numbers. The first 2 are the amount of red, the second 2 the amount of green and the final 2 the amount of blue.
Note also that in CSS we use the American spelling for colour so we drop the u, eg color. If you happen to be American then this won't be a problem but for others it is something to keep in mind.
The color property allows us to specify the colour of the text.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
The background-color property allows us to specify the background colour for the element.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
Picking good colours for your content can have a huge impact on how it looks.
If you want to learn more about picking good colour schemes head on over and check out our Graphic Design Tutorial section on Colour.
Spacing is another area which is easy to implement but hard to master. There are a lot of subtle little details to understand once we start creating complex layouts. We'll cover the topic in more detail when we look at the box model in a later section. Don't let this deter you from playing about and experimenting with the properties below, however, in the mean time.
Similar to font-size, they may be specified in a variety of units but we'll stick to just pixels for now to keep it simple.
padding refers to the space around out content. We've included the background-color property here as well just to make it a bit easier to see what is happening.
We may specify the padding in 3 methods:
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
margin is similar to padding in that is affects the spacing around the content. It is a second area outside the padding however. Compare the example below to the one above for padding and note where the background colour ends.
Similar to padding, you may specify a single value, or two or four.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
The border is inbetween the padding and margin. I'll outline basic usage here but there are various properties available to control the look of the border with greater detail so I would recommend having a look at the Border Properties in the CSS specification.
The various aspects of the border which you may control are:
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
Now let's put all the above properties together and see what effect it has. They may have seemed a little boring when looked at individually but as you'll see in the example below, even with just simple tweaks, we can really make our content shine.
On the weekend I got all my watches and attached them together into a belt.
It turned out to be a waist of time.
I know we haven't looked at many rules yet so for these activities use some of the rules we have seen in the examples. As you change the code in your files you may need to refresh the page to see the changes (rather than just reloading it), this is because the browser will cache the page by default.