That leaves only an explanation of the difference between italic and oblique text. For that, it's easiest to turn to Figure 5-24, which illustrates the differences very clearly.

Figure 5-24

Figure 5-24. Italic and oblique text in detail

Basically, italic text is in some way its own font, with small changes made to the structure of each letter to account for the Tuesday 07th of February 2012 01:03:31 AM

CSS Tutorials > Making Lists Look Nicer with CSS

Making Lists Look Nicer with CSS

Standard HTML lists are usually pretty boring - a few indented lines with bullets or numbers down the left side. However, with the power of CSS, you can really get creative with your lists! Read on for details...

Controlling indentation

CSS allows you to have more control over the level of indentation of the list items. This is great for those times when your lists start veering across the page, ruining the nice, perfectly-aligned look of your design.

You can adjust the amount of indentation that a list uses by setting both the margin-left and padding-left properties for the ul selector. For example:

ul
{
margin-left: 0;
padding-left: 0;
}

Note that you have to specify both margin-left and padding-left for this to work properly across all browsers.

So let's create a simple list inside a dark rectangle:

<div style="background-color: #3C8B8B">
<ul style="margin-left: 0; padding-left: 0;">
<li>Rover the dog</li>
<li>Fluffy the cat</li>
<li>Jack the rabbit</li>
</ul>
</div>

This will produce the following list:

  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

The trouble is - our list bullets are outside the rectangle - invisible even, on some browsers! This is because, by default, a list item's bullet is outside the list item's CSS box. We can fix this problem by adding a bit of padding to the list:

<ul style="margin-left: 0; padding-left: 30px;">

This produces the following effect:

  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

That's more like it! So now we can control exactly how far our lists indent, for example:

<ul style="margin-left: 0; padding-left: 5px;">
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

Using different bullets

Another great thing you can do with CSS is change the style of bullets. This is achieved using the list-style-type property. For example, to change the bullets to squares:

<ul style="list-style-type: square;
margin-left: 0; padding-left: 30px;">
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

There are also many types of numbering systems you can use for numbered lists. For example:

list-style-type: lower-roman;
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit
list-style-type: lower-alpha;
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit
list-style-type: decimal-leading-zero;

(Only works on some browsers)

  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

For a full list of bullet types that you can use in lists, see the W3C CSS Spec.

Using images for bullets

You can even use images for list bullets!

list-style-image: url("images/smiley.gif");
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

Inline lists

Another really useful thing you can do with CSS is create inline lists, using display: inline. For example:

ul, li
{
display: inline;
}
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

Now that the list is not constrained to being displayed in a vertical row, you have a lot more control over the layout. For example, by adding in a few borders and background colours, you can give the list items a "button" effect:

ul, li
{
display: inline;
}
li
{
border: solid 1px white;
padding: 5px;
margin: 5px;
background-color: #339999;
}
  • Rover the dog
  • Fluffy the cat
  • Jack the rabbit

You can see that, while the basic HTML for our list has remained the same throughout this tutorial, we have managed to change the look of the list fairly radically through the use of CSS. Pretty cool!

This has hopefully given you a taste of some of the neat things you can do with CSS and lists. For more info on formatting lists with CSS, see the W3C Specification.

The End

That's the end of this tutorial. We hope you found it useful. If you're still stuck and would like further help, check out our online Help Forums, where you can get assistance from members of my and other webmasters.

If you would like to offer us feedback on this or any of the tutorials, please contact us. Have fun!


fontIE4 P/Q IE5 P/Y NN4 P/P Op3 Y/-

This is ashorthand property for the other font properties. Any of these valuesmay be omitted except for font-size andfont-family, which are always required for a validfont declaration. Note the following incorrect examples.

Example

This is used to declare a specific fontto be used, or a generic font family, or both. Note that the use of aspecific font family is dependent on the user having said font EM {color: #999999;}
Figure 6-9

Figure 6-9. Different colors for different elements

Thanks to the inheritability of color, it's theoretically possible to set all of the ordinary text in a document to be a color such as red by declaring BODY {color: red;}. This should cause all text which is not otherwise styled (such as anchors, which have their own color styles) to be red. This should not affect elements such as horizontal rules ( HR ) or images. However, early versions of Explorer did inherit colors onto HR elements,

Figure 7-86

Figure 7-86. Placing the bullets inside and outside list items

CSS2, by the way, provides a good deal more control over the positioning of the bullets (called "markers" in CSS2); again, this is discussed in Chapter 10, "CSS2: A Look Ahead".

7.7.4. List Styles In Shorthand

For brevity's sake, you can combine the three list-style properties into a convenient singlecan't be read by the human eye. You can do this using completely correct CSS and a bug-free browser. Here's the easiest way to see it:

UL {font-size: 75%;}

This seems simple enough: the text in unordered lists should be 75% normal size. Ah, but what happens if you have unordered lists nested inside unordered lists? You get the results shown in Figure 11-21, that's what.

Figure 11-21

Figure 11-21. Help me

border-rightIE4 P/P IE5 P/Y NN4 N/N Op3 P/-

This shorthand property defines thewidth, color, and style of the right border of an element. The usualcaveats about border-style apply.border-right-widthIE4 P/P IE5 P/Y NN4 B/B Op3 Y/-

Sets thewidth of the right border of an element, which will inherit theelement's background, and may have a foreground of its own (seeborder-style). Negative length values are notpermitted.

border-styleIE4 P/Y IE5 P/Y NN4 P/P Op3 Y/-

Sets the style of the overall border of