CSS list-style list style attribute usage

Source: Internet
Author: User

Parse CSS list style attributes list-style

The list-style attribute can be frequently used in list-item objects on pages, but it is rarely used. Generally, it is almost OK to reset the entire page to none. Many people may not know the details of the attribute list-style-type, it is more likely that the concepts of the attribute list-style and the attribute list-style-type will be vague. It is necessary to re-learn it, so it is sorted as follows.

Meaning and usage

List-style short attribute sets all list attributes in a declaration.

Description
This attribute is a short attribute that covers all other list style attributes. Since it applies to all the elements whose display is list-item, it can only be used for li elements in common HTML and XHTML, but in fact it can be applied to any element, it is inherited by the list-item element.

You can set the following attributes in sequence:

• List-style-type
• List-style-position
• List-style-image


◆ List-style

Definition: it is used to set the short attribute of all attributes of a list in a declaration. This attribute is a short attribute that covers all other list style attributes, only applies to objects with the display value equal to list-item (such as li objects ).

Related: list-style-imagelist-style-positionlist-style-type

◆ List-style-image

Description: sets or retrieves images marked as object list items. If the value of this attribute is none or the image with the specified url address cannot be displayed, the list-style-type attribute takes effect.

Valid value:

None: default value. Image unspecified

Url: specifies an image using an absolute or relative url address.


Set the image to the project tag in the list:

The code is as follows: Copy code

Ul
  {
List-style-image: url ("/I/arrow.gif ");
List-style-type: square;
  }

Example

The code is as follows: Copy code

<Html>
<Head>
<Style type = "text/css">
Ul
{
List-style-image: url ('/I/eg_arrow.gif ')
}
</Style>
</Head>

<Body>
<Ul>
<Li> Coffee </li>
<Li> tea </li>
<Li> Coca-Cola </li>
</Ul>
</Body>

</Html>

◆ List-style-position

Description: sets or retrieves how to sort the list items marked as objects by text. If the left outer patch (margin-left) of a list project is set to 0, the List project tag is not displayed. The minimum value of the left outer patch (margin-left) can be set to 30. Only applies to objects with a display property value equal to list-item. Such as li object.

Valid value:

Outside: default value. The List Project tag is placed outside the text and the surrounding text is not aligned according to the tag

Inside: The list item tag is placed within the text and the surrounding text is aligned according to the tag

Instance
Specifies the position marked by the list item in the list:

The code is as follows: Copy code

Ul
  {
List-style-position: inside;
  }


Instance

The code is as follows: Copy code

<Html>
<Head>
<Style type = "text/css">
Ul. inside
{
List-style-position: inside
}

Ul. outside
{
List-style-position: outside
}
</Style>
</Head>

<Body>
<P> The value of list-style-position in this list is "inside": </p>
<Ul class = "inside">
<Li> Earl Grey Tea-a black Tea </li>
<Li> Jasmine Tea-a magical "full-featured" Tea </li>
<Li> Honeybush Tea-a pleasant fruity Tea </li>
</Ul>

<P> The value of list-style-position in this list is "outside": </p>
<Ul class = "outside">
<Li> Earl Grey Tea-a black Tea </li>
<Li> Jasmine Tea-a magical "full-featured" Tea </li>
<Li> Honeybush Tea-a pleasant fruity Tea </li>
</Ul>
</Body>
</Html>

Browser support

All browsers support the list-style-position attribute.

Note: Any version of Internet Explorer (including IE8) does not support the attribute value "inherit ".


◆ List-style-type

Description: sets or retrieves the default marker used by the object list items. If the value of list-style-image is none or the image with the specified url address cannot be displayed, this attribute will take effect.

Instance
In this example, the type of the list is changed:

The code is as follows: Copy code

<Html>
<Head>
<Script type = "text/javascript">
Function changeList ()
  {
Document. getElementById ("ul1"). style. listStyle = "decimal inside ";
  }
</Script>
</Head>
<Body>

<Ul id = "ul1">
<Li> Coffee </li>
<Li> Tea </li>
<Li> Water </li>
<Li> Soda </li>
</Ul>

<Input type = "button" onclick = "changeList ()"
Value = "Change list style"/>

</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.