Sams Teach Yourself CSS in 10 Minutes
Styling the <a> Element
Text links are generally only active when you mouse over the actual text area. You can increase this active area by applying display: block; to the <a> element. This will change it from inline to block level, and the active area will extend to the full width of the list item. When the <a> element is block level, users do not have to click on the text; they can click on any area of the list item. Style the <a> elements with display: block; as shown in Listing 15.5. Listing 15.5. CSS Code for Setting display: block
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; } To remove the underlines on the links, use text-decoration: none; (see Listing 15.6). Listing 15.6. CSS Code for Removing Link Underlining
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; }
To set the background color, you can use the shorthand rule background: #036; as shown in Listing 15.7. This color can be changed to suit your needs. Listing 15.7. CSS Code for Setting Background Color
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; background: #036; }
Next, the text color should be set to #fff (the hex color for white). See Listing 15.8. Like the background color, text color can be changed to suit your needs. Listing 15.8. CSS Code for Setting Text Color
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; background: #036; color: #fff; }
You will need .2em padding on the top and bottom of the <a> element, and .5em padding on both sides. Rather than specify these amounts in separate declarations, you can use one shorthand declaration to define them all. In this case you will use padding: .2em .5em, which will apply .2em of padding on the top and bottom of the <a> element, and .5em on both sides as shown in Listing 15.9. Listing 15.9. CSS Code for Setting Padding
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; background: #036; color: #fff; padding: .2em .5em; }
To provide some space between the list items, you can add a border on the bottom of each list item. In this case you will use border-bottom: #fff as shown in Listing 15.10. Listing 15.10. CSS Code for Setting Borders
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; background: #036; color: #fff; padding: .2em .5em; border-bottom: 1px solid #fff; }
Set the width of the <a> element using width: 7em; as shown in Listing 15.11 and illustrated in Figure 15.3. This width can be changed to suit your needs. Listing 15.11. CSS Code for Setting Width
ul#navigation { margin-left: 0; padding-left: 0; list-style-type: none; } ul#navigation a { display: block; text-decoration: none; background: #036; color: #fff; padding: .2em .5em; border-bottom: 1px solid #fff; width: 7em; }
Figure 15.3. Screenshot of list with <a> element styled.
|
Категории