Custom Search

How To Create Vertical Spacing Between Lists Using Html Li Tag & Css

This is how to create vertical spacing between lists using the HTML tag and CSS. I've kept in mind to keep the code in compliance to XHTML Strict validation with W3C standards. I validate to the Strict standards strictly to Search Engine Optimize the page. Here is a sample of an unordered list code in plain HTML:

list item 1 list item 2

item 2 sub-list 1 item 2 sub-list 2

List item 3

The above HTML code is rendered in Mozilla browser (i.e. Firefox 3.x and greater), IE 7.x and greater and Safari 3.2 and greater on my Vista Home Premium as follows;however, please note the html tags that are surrounding the inner tags. This is required for W3C strict validation;otherwise, you'll receive errors.

list item 1
list item 2

item 2 sub-list 1
item 2 sub-list 2

List item 3

The above UL and LI tags format as expected. The only bug I encounterd was with Internet Explorer 7.x and greater is the second UL tag didn't properly have the vertical spacing. So to resolve this bug in IE simply add margin-top to the second UL tag as so:

list item 1
list item 2


item 2 sub-list 1
item 2 sub-list 2


List item 3

Oddly enough, there was no extra spacing with Firefox 3.x and greater and Safari 3.2 and greater with this last bit of code. In other words, margin-top:10px didn't have any effect with Firefox and Safari.

By: Victor Kimura

Article Directory: http://www.articledashboard.com

CSS Tutorial, tips, guides. Learn CSS programming. Victor Kimura
Tutorial CSS Please view the original article to properly view the code and step-by-step snapshots here:CSS List-How to Create Vertical Spacing Between LI Tags

© 2005-2011 Article Dashboard