Lists have some special styling considerations. There are options for controlling what “image” to use for bullets, how to position the bullets, and the type of bullet or numbering to use for the list. These options can all be defined in a single composite list-style attribute that lets you control all three options:
The image, which can be independently set using list-style-image, which simply specifies the image that will be used for bullets, with none indicating to use the built-in bullet styles. This supports images that you specify by using the url("image") to use a downloaded image, but graphic commands such as gradient (which we will be covering in a future chapter) can be used. An example of this would be using the style:
Resulting in:
The list position is where the bullet will be displayed for multi-lined items. You can independently specify this attribute using list-style-position, with the options for this being inside or outside. The default is outside where the text will align with the text above it, while inside aligns the text with the bullet. The image below shows the two options.
Finally, the type is simply the way to display the bullet or number. This can be independently set using list-style-type. Unordered lists and Ordered lists have different options here.
For unordered lists, the options are none, disc, circle, square, or a string such as “*” or "👍" or whatever string you wish to use. This image below shows these different options
The ordered list have their own list, with several language specific options as well. Here are the common formats:
As long lists can be difficult to read so it is often that the list will have different colors to distinguish the different items making it easier to understand the list. CSS supports this option by using a state delimiter similar to that for fonts. :nth-child() is used to specify the count. This is done using mathematic notation so 2n is ever second item while 2n+1 would be every odd item. Since these two options are so common, CSS provides the shortcuts odd and even. So li:nth_child(odd) would be used to specify the styling of odd list items while li:nth_child(even) covers the even items.
This is a bit difficult to grok without a demo, so lets create a list that has 3 different colors, red for 1,4,7,… then green for 2,5,8, then blue for 3, 6, 9… . Here is the code for the style sheet
The code for the lists
With the result being:
The demo for all the lists shown in this chapter is available on the git repository.
Of course, if we can style lists, we should be able to style tables, so lets look at tables next.
A cheat sheet covering the basics of CSS.
A brief look at what CSS is and how it came to be.
A look at the three different ways to add style to your document.
Setting the style for different types of elements.
An easy way of having multiple styles on the same element type and across different elements.
The use of named colors, the RGB color model, and creating RGB colors.
Using hexadecimal color codes and other color models.
Controlling what text looks like.
The box model controls how elements are positioned within their layout box.
Anchor element states and turning a link into a button.
A total conversion of Hunt the Webbus with a Christmas Theme.
Lists can have style applied to their layout, placement, and bullet.
Tables have a grid as well as rows and columns that can be controlled.
The project for this chapter is a variation of a classic text game
My solution for the Webbus project
Converting the Webbus game into a Christmas game.