CSS Lists
CSS (Cascading Style Sheets) allows you to style HTML lists, such as unordered lists (ul) and ordered lists (ol), using various properties and selectors. Here are some common CSS properties and techniques you can use to style lists:
- List Style Type: You can change the appearance of list items’ markers using the
list-style-type
property. It accepts values like “none” (no markers), “disc” (filled circle), “circle” (hollow circle), “square” (filled square), “decimal” (1, 2, 3…), “lower-alpha” (a, b, c…), “upper-alpha” (A, B, C…), and more.
css
ul {
list-style-type: circle;
}
ol {
list-style-type: decimal;
}
- List Style Image: You can use a custom image as the marker for list items using the
list-style-image
property. This property specifies the URL of the image you want to use as the marker.
css
ul {
list-style-image: url('custom-marker.png');
}
- List Style Position: By default, the list item marker appears outside the content box of the list item. You can change this using the
list-style-position
property. Set it to “inside” to place the marker inside the content box.
css
ul {
list-style-position: inside;
}
- List Item Styling: You can style individual list items using the
li
selector. This allows you to change the appearance of each list item independently.
css
li {
color: red;
font-weight: bold;
}
- Nested Lists: CSS allows you to style nested lists differently by using descendant selectors. You can target nested lists inside other lists and apply specific styles.
css
ul ul {
/* Styles for nested unordered lists */
}
ol ol {
/* Styles for nested ordered lists */
}
These are just a few examples of how you can style lists with CSS. There are many more properties and techniques available to customize the appearance of lists according to your needs.