|
A c t i o n f o r L i b r a r i e s
— M a y 2 0 0 4
The Internet ConnectionBy Michael Sauers
Rethinking Lists: Coding in CSS (Part II) Here's our code for the list, with the addition of anchors to create hyperlinks. (I've left the URLs out to keep the code simple. This will not affect the end result we want.)
XHTML Code Now let's put each of our list items into a box of equal size and center the content. With this coding, each item will begin to look like a Web page button.
CSS Code The next step will be to color the boxes. However, we don't want to change the background color of the items. Although this would accomplish what we want in the short-term, it will cause a problem later on. So let's add a background color to the anchors instead.
CSS Code The selectors in this case have been set to affect only anchors that are children of unordered lists (ul a). If we do not include "ul" in the selector, the code would affect every anchor on the Web page, which is not what we want. We want only to color the text in the list. In the code, the color property turns the text black against the green set for the background of the anchor. The "text- decoration property" turns off underlining on the anchors. Setting the display property to "block" forces the anchor to be treated as something that fills in the entire box we created. If we did not include this setting, the background color would display only behind the linked text and not fill the entire box. Lastly, the "padding" property provides a small bit of space between the edges of the text and the edge of the background color, along with a margin setting that allows a small space between the background color and the box. Here's the result:
CSS Code This changes the background color of the box to a lighter shade of green and the link text to black when the mouse pointer moves over the link. Here is our result: There is one small difference between the results in Mozilla-based browsers and Internet Explorer. In IE, the hover effect works only when the mouse pointer is over the linked text. In Mozilla-based browsers, the hover works whenever the mouse pointer is over any point within the box, not just the linked text. Next Article | Previous Article | Table of Contents | BCR Publications Comments to:
shoffhin@bcr.org |