
Has CSS always been somewhat of a mystery to you? Do you sometimes wonder what the benefits are to using CSS? Would you like to learn how to style HTML unordered list?
If you said yes to everything above, then this article is for you. I recently was searching the web for the easiest way to customize my unordered list using CSS, and found many possible solutions. However, none of the articles really explained what the CSS code was doing and why.
Article Guide: Real quick, when I use brackets [] it means I'm calling your attention to just that line of code. Do not insert brackets into your CSS code thinking this is part of CSS, because it is not. I will always present images with the actual code displayed. Use that instead. Thanks!
I decided to write this article because I was trying to find the best way to design unordered HTML list for my own site. Because of my CSS layout structure, I was having problems just assigning CSS to the <UL> and <LI> tags. So the simple solution is to define a CSS class. Let's begin.
Okay, so why would we want to control an unordered list through CSS? Well, it allows us to add neat design elements such as graphics to replace those nasty looking bullets. It also allows us to get very specific with positioning of these graphics. Using CSS to control the list also allows for repetition of graphics without slowing down the page loading.
Code Example #1
Below is a normal looking unordered list.It looks pretty bland doesn't it? So how do we spice it up? Keep reading the article and follow along with the referenced code examples.
To the right you will see the finished CSS code to create an unordered list. Take a moment to read through
(Figure One) - Explained if you haven't already done so. Allow me to further expound on the .orangelists li class now. The [list-style-type: none;] sets the default bullets that you would normally see if you created an unordered html list, to go away. So why do we do this? Well, it's so we can make room for our cool graphic to represent as a bullet point. In my case, I have orange check marks. Open Adobe Photoshop to create your graphic, or use a free graphic. The code [background:url(yourimage.gif) no-repeat 0 50%;] sets the image to be used as the bullet within the unordered list. This image gets attached to each <LI> item line you have in your html code.
To conclude this tutorial, I just want to quickly cover what the property [padding-left:30px;] is controlling. This parameter is controlling the space between the graphic and the text. If you adjust that padding to say 10px, the graphic will be very close to the text, and it probably won't look visually correct.
My Follow Up Notes:
This is just one way of controlling an unordered list using CSS. I used the class method because it worked for my situation. However, you can apply this CSS directly to the UL and LI HTML elements. That means instead of creating a class like .orangelists, you can simply reference the <UL> tag and write the CSS code to control it.
Possible Spacing Issue:
One last thing, you might run into a spacing issue between your list items. You can either solve this problem by using <BR> tags after each ending <LI> tag, or set the
[line-height] property to a value greater then 100%. It is probably easier to use the line-height property to fix the spacing.
I hope you found this tutorial useful. Keep checking back as I will continue to add more content on a variety of subjects.
If you found this article helpful, but need further help on a web project I am available for hire. Simply use my contact form by clicking here.