Like other items, there are some CSS properties to design and style HTML Lists too.
CSS List Properties allow you to :
The type of list item marker is specified by list-style-type property:
CSS List Properties allow you to :
- Set different list item markers for ordered lists
- Set different list item markers for unordered lists
- Set an image as list item marker
There are two types of lists in HTML:
- Ordered Lists - The list items are marked with numbers or alphabets
- Unordered Lists - The list items are marked with bullets
With CSS list items can be styled further. An image can be used as list item marker.
The type of list item marker is specified by list-style-type property:
ul.a {
list-style-type: circle;
}
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
CSS allows us to use any image as the list item marker. Just use the list-style-image instead of list-style-type, and place the URL before :
ul {
list-style-image: url('sqblue.gif');
}
Example: http://css3wdesign.net16.net/image-marker.html
In the above mentioned example, the image is slightly bigger than the usual bullet. The image specified as the image marker, will be slightly more bigger in IE and Opera than the image in Safari, Chrome and Firefox.
To overcome this, you have to specify all of the image attributes independently. Below is a Crossbrowser solution for this:
In the above mentioned example, the image is slightly bigger than the usual bullet. The image specified as the image marker, will be slightly more bigger in IE and Opera than the image in Safari, Chrome and Firefox.
To overcome this, you have to specify all of the image attributes independently. Below is a Crossbrowser solution for this:
Crossbrowser solution
The below code will show the image marker in all browsers equally:
ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}
ul li {
background-image: url(sqblue.gif);
background-repeat: no-repeat;
background-position: 0px 5px;
padding-left: 14px;
}
Try using this URL in all browsers: http://css3wdesign.net16.net/image-marker2.html
Explained example:
and the list will be without any style. Below is the output of the list-style: none;
Explained example:
- For ul:
- to remove the list item marker first, set the list-style-type to none
- set the margin to 0 (for crossbrowser compatibility)
- For ul li
- place URL of image in the background-image property and set it to the no-repeat
- specify the image position using background-position (left 0px and down 5px)
- position the text in the list item: padding-left
list-style: none;
Sometime, we don't need to specify any of the list-item style. CSS also allows to do so.
Use the
list-style: none;
- Item one
- Item two
- Item three
- Item four
Here is the list of all values, which can be used in list-style-type.
Post a Comment
Suggestions will be greeted.