Anda di halaman 1dari 2

8/4/13

CSS Styling Lists


Search w3schools.com: Select Language

HOME

HTML

C SS

JAVASC RIPT

JQUERY

XML

ASP.NET

PHP

SQL

MORE...

R EFER ENC ES

EXAMPLES

FO R UM

ABO UT

Get Certified
Study Web Technologies and get a diploma at w3schools.com

SHARE THIS PAGE

Like

76k

CSS Basic
CSS HOME CSS Introduction CSS Syntax CSS Id & Class CSS How To

CSS Lists
Previous
The 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 the list item marker

WEB HOSTING

Next Chapter

Best Web Hosting eUK Web Hosting UK Reseller Hosting Domain, Hosting & Email

CSS Styling
Styling Backgrounds Styling Text Styling Fonts Styling Links Styling Lists Styling Tables

WEB BUILDING
XML Editor - Free Trial! FREE Website BUILDER FREE Website C reator Best Website Templates

List
In HTML, there are two types of lists: unordered lists - the list items are marked with bullets ordered lists - the list items are marked with numbers or letters With CSS, lists can be styled further, and images can be used as the list item marker.

CSS Box Model


CSS Box Model CSS Border CSS Outline CSS Margin CSS Padding

STATISTICS
Browser Statistics

Different List Item Markers


The type of list item marker is specified with the list-style-type property:

OS Statistics Display Statistics

Example
u l . a{ l i s t s t y l e t y p e :c i r c l e ; } u l . b{ l i s t s t y l e t y p e :s q u a r e ; } o l . c{ l i s t s t y l e t y p e :u p p e r r o m a n ; } o l . d{ l i s t s t y l e t y p e :l o w e r a l p h a ; }
Try it yourself Some of the values are for unordered lists, and some for ordered lists.

CSS Advanced
CSS Grouping/Nesting CSS Dimension CSS Display CSS Positioning CSS Floating CSS Align CSS Pseudo-class CSS Pseudo-element CSS Navigation Bar CSS Image Gallery CSS Image Opacity CSS Image Sprites CSS Media Types CSS Attribute Selectors CSS Summary

An Image as The List Item Marker


To specify an image as the list item marker, use the list-style-image property:

Example
u l { l i s t s t y l e i m a g e :u r l ( ' s q p u r p l e . g i f ' ) ; }
Try it yourself The example above does not display equally in all browsers. IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari. If you want the image-marker to be placed equally in all browsers, a crossbrowser solution is explained below.

CSS Examples
CSS Examples CSS Quiz CSS Certificate

CSS References
CSS Reference CSS Selectors CSS Reference Aural CSS Web Safe Fonts CSS Units CSS Colors CSS Color Values CSS Color Names CSS Color HEX

Crossbrowser Solution
The following example displays the image-marker equally in all browsers:

Example
u l { l i s t s t y l e t y p e :n o n e ; p a d d i n g :0 p x ; m a r g i n :0 p x ; } u ll i { b a c k g r o u n d i m a g e :u r l ( s q p u r p l e . g i f ) ; b a c k g r o u n d r e p e a t :n o r e p e a t ; b a c k g r o u n d p o s i t i o n :0 p x5 p x ; p a d d i n g l e f t :1 4 p x ; }
Try it yourself Example explained:

w3schools.com/css/css_list.asp

1/2

8/4/13

CSS Styling Lists


For ul: Set the list-style-type to none to remove the list item marker Set both padding and margin to 0px (for cross-browser compatibility) For all li in ul: Set the URL of the image, and show it only once (no-repeat) Position the image where you want it (left 0px and down 5px) Position the text in the list with padding-left

List - Shorthand property


It is also possible to specify all the list properties in one, single property. This is called a shorthand property. The shorthand property used for lists, is the list-style property:

Example
u l { l i s t s t y l e :s q u a r eu r l ( " s q p u r p l e . g i f " ) ; }
Try it yourself When using the shorthand property, the order of the values are: list-style-type list-style-position (for a description, see the CSS properties table below) list-style-image It does not matter if one of the values above are missing, as long as the rest are in the specified order.

More Examples
All the different list-item markers for lists This example demonstrates all the different list-item markers in CSS.

All CSS List Properties


Property list-style list-style-image list-style-position list-style-type Description Sets all the properties for a list in one declaration Specifies an image as the list-item marker Specifies if the list-item markers should appear inside or outside the content flow Specifies the type of list-item marker

Previous

Next Chapter

Top 10 Tutorials
HTML Tutorial HTML5 Tutorial C SS Tutorial C SS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial

Top 10 References
HTML/HTML5 Reference C SS 1,2,3 Reference C SS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML C olors

Examples
HTML Examples C SS Examples XML Examples JavaScript Examples HTML DOM Examples XML DOM Examples AJAX Examples ASP.NET Examples Razor Examples ASP Examples SVG Examples

Quizzes
HTML Quiz HTML5 Quiz XHTML Quiz C SS Quiz JavaScript Quiz jQuery Quiz XML Quiz ASP Quiz PHP Quiz SQL Quiz

Color Picker

Statistics
Browser Statistics Browser OS Browser Display

RE P O RT E RRO R

HO ME

TO P

P RI N T

FO RU M

A BO U T

A D V E RT I SE WI T H U S

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use and privacy policy. C opyright 1999-2013 by Refsnes Data. All Rights Reserved.

w3schools.com/css/css_list.asp

2/2

Anda mungkin juga menyukai