Home  >  Article  >  Web Front-end  >  CSS: Detailed explanation of the usage of list-style list style

CSS: Detailed explanation of the usage of list-style list style

黄舟
黄舟Original
2017-06-29 09:17:563971browse

AnalysisCSS list styleAttribute list-style

In daily production pages, the attribute list-style can be commonly used in list-item objects, but it is not used deeply. Generally, it is almost OK to reset the entire page by setting it to none. Maybe many people, including myself, don’t know much about the more detailed attributes of the attribute list-style-type. It is more likely that the attributes list-style and The concept of attribute list-style-type is relatively vague. It is now necessary to bring it up and learn it again, so it is organized as follows.

Yihe usage

list-style shorthand attribute sets all list attributes in one statement.

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

The following attributes can be set in order:

•list-style-type
list-style-position
list-style -image

##◆list-style

Definition: A shorthand attribute used to set all attributes of a list in one declaration. This attribute is a shorthand attribute that covers Removes all other list style properties and only acts on objects with a 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 the list item mark as an object Image. If the value of this attribute is none or the image at the specified URL address cannot be displayed, the list-style-type attribute will take effect.

Value:

none: Default value. Do not specify an image

url(url): Specify an image using an absolute or relative url address

Set the image as an item tag in the list:

ul
  {
  list-style-image:url("/i/arrow.gif");
  list-style-type:square;
  }

Example

<html>
<head>
<style type="text/css">
ul 
{
list-style-image: url(&#39;/i/eg_arrow.gif&#39;)
}
</style>
</head>
<body>
<ul>
<li>咖啡</li>
<li>茶</li>
<li>可口可乐</li>
</ul>
</body>
</html>

◆list-style-position

Description: Sets or retrieves how the list item tags as objects are arranged according to the text. If a list item's left margin (

margin-left) is set to 0, the list item mark will not be displayed. The margin-left can be set to a minimum of 30. Only works on objects with a display attribute value equal to list-item. Such as li object.

Value:

outside: Default value. The list item mark is placed outside the text, and the surrounding text is not aligned according to the mark

inside: The list item mark is placed inside the text, and the surrounding text is aligned according to the mark

Example

Specifies inside the list Position of list item mark:

ul
  {
  list-style-position:inside;
  }

Example

<html>
<head>
<style type="text/css">
ul.inside 
{
list-style-position: inside
}
ul.outside 
{
list-style-position: outside
}
</style>
</head>
<body>
<p>该列表的 list-style-position 的值是 "inside":</p>
<ul class="inside">
<li>Earl Grey Tea - 一种黑颜色的茶</li>
<li>Jasmine Tea - 一种神奇的“全功能”茶</li>
<li>Honeybush Tea - 一种令人愉快的果味茶</li>
</ul>
<p>该列表的 list-style-position 的值是 "outside":</p>
<ul class="outside">
<li>Earl Grey Tea - 一种黑颜色的茶</li>
<li>Jasmine Tea - 一种神奇的“全功能”茶</li>
<li>Honeybush Tea - 一种令人愉快的果味茶</li>
</ul>
</body>
</html>

Browser support

All browsers support the list-style-position attribute.

Note: The attribute value "inherit" is not supported by any version of Internet Explorer (including IE8).

◆list-style-type

Description: Sets or retrieves the default tag used by the object's list items. This attribute will take effect if the value of the list-style-image attribute is none or the image at the specified URL address cannot be displayed.

Example

This example changes the type of the list:

<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>

The above is the detailed content of CSS: Detailed explanation of the usage of list-style list style. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn