To get you started here are some things you can do with your first attempt of using CSS;
Capitalizing words
You can use CSS to manipulate text. One effect is to capitalize words.
This uses the text-transform property, which has four possible values;
- capitalize
- uppercase
- lowercase
- none
In the style sheet we will asign this rule to the selector class caps,
and apply it to a <p> tag.
.caps
{
text-transform: capitalize;
}
So when you apply the class caps
<p class="caps">some text<p>
you get
some text
Different cursors
You can even use CSS to alter how the cursor reacts. For example when the cursor hovers over a hyperlink it changes
from a arrow to a pointing hand. With CSS you can change this to one of several looks, we will use it to change the cursor
to a crosshair when hovering over hyperlinks. As with the above example we will apply this to a selector class called
xhair.
.xhair
{
cursor: crosshair;
}
We will apply this to the link;
<a href="#" class="xhair">Cursor change</a>
Example Cursor change here.
Changing hyperlinks
Altering hyperlinks is different to changing other elements. This is because they have four states, all of which can be individually affected.
You can make some changes to all the states with one declaration, for example colour.
a {color: red;}
When changing individual states care must be taken in the declaration order. The order is;
- a:link
- a:visited
- a:hover
- a:active
A:hover must be declared after the A:link and A:visited rules.
This is because of the cascading rules will overide the A:hover rule.
A:active needs to be declared after A:hover,
the active rule will be applied when the user both activates and hovers over the hyperlink
(Quackit.com 2008).
The following example will both underline and overline a link when it is hovered over using the
text-decoration property, and change the text to orange and uppercase when in the hover state;
.lines a:link, a:visited
{
text-decoration: none;
}
.lines a:hover, a:active
{
color: orange;
text-decoration: underline overline;
text-transform: uppercase;
}
We will apply this to the link;
<div class="lines">
<a href="#">text-decoration</a>
</div>
Horizontal lists
With the best-approach pratice of coding and the seperating of content from style CSS has devolped the use of HTML tags.
One example of this is how lists are used. Traditionally lists are vertical, but by using the CSS property
display you can format a list to appear horizontally. This approach has been adopted to create
navigation bars for many websites.
.horizontal li
{
display: inline;
}
This has the following effect;
When applied with rules on hyperlinks you can generate navigation bars that you used only to done by using Javascript.
Look at listamatic for many examples of this.
Example:
Back to top