Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 

Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format



Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 

CSS Tip:
Customize Your HTML Tags

by Tom Dahm,
Chief Operations Officer,
NetMechanic, Inc.

  
December 2000
(Part 2)
Vol. 3, No. 18
 • Promotion Tip
 • CSS Tip
 • Design Tip
  

One of the great things about Cascading Style Sheets is that they allow you to adjust the behavior of HTML tags, giving you more control over your Web page. With a little work, you can customize tags to work the way you want them to. In the past, you pretty much had to live with the way your browser rendered each tag.

For example, take a simple HTML list, like the one shown below.

<UL>
<LI>List Item 1
<LI>List Item 2
</UL>

When rendered by your browser, this simple HTML element looks like this:

  • List Item 1
  • List Item 2

Two common questions asked by beginning HTML coders are:

  1. Can I customize the bullets used in my list?
  2. Can I control the amount of white space above and below my list?

With basic HTML, the answer to both questions is "No, you can't." With style sheets, the answer to both is "Yes, absolutely."

In a previous story we showed you how to customize the bullets used in your list. In this story, we'll show you how to control the white space above and below your list.

Under CSS every HTML element is contained in a "block," a rectangle that surrounds the element. This block itself has style properties that you can adjust, letting you control the amount of white space around the element.

For example, if we displayed the block surrounding our HTML list, it would look something like this:

The amount of white space around our bullets is controlled by two properties: padding and margin. The element's padding defines the amount of white space between our bullets and the block border. The element's margin defines the amount of white space between block border and the text above and below the list itself. This is the space we want to adjust to customize our bullet list.

To do this, we can use the STYLE attribute to set a pair of properties called "margin-top" and "margin-bottom." We could use the single property "margin" to define both the top and bottom margins at once, but some versions of Internet Explorer don't handle this property correctly, so we'll set the top and bottom margins separately.

Here's the code:

<P STYLE="background-color:tan">Text 
   above our list</p>
<UL STYLE="margin-top:0px; margin-bottom:0px;">
<LI>List Item 1
<LI>List Item 2
</UL>
<P STYLE="background-color:tan">Text 
  below our list</p>

Setting "margin-top:0px" tells the browser to set the top margin to zero pixels. If we were using this list in an actual Web page, we'd probably use some value other than zero. But for this example, a zero value helps to dramatize the way we're changing the tag's behavior.

To show the relation of our list to the surrounding text, we've also added a paragraph of text above and below our list, and we've set the background color property of these paragraphs to clearly show where the bullet list element begins.

This makes our list appear as shown below.

Notice that the amount of white space between our list and the surrounding paragraphs hasn't changed yet. That's because our paragraphs also have margins associated with them. To fully control the white space around our list, therefore, we also need to apply a style to each of our paragraphs. The code below shows how to do this.

<P STYLE=" margin-bottom:0px; background-color:tan">Text 
  above our list</p>
<UL STYLE="margin-top:0px; margin-bottom:0px;">
<LI>List Item 1
<LI>List Item 2
</UL>
<P STYLE="margin-top:0px; background-color:tan">Text 
  below our list</p>

Now the list appears as shown below.

Notice that we've completely eliminated the white space around the bullet list. This effect will work under Internet Explorer Version 4 and higher, as well as under Netscape Navigator Version 6. Version 4 of Netscape doesn't support this effect.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.