CSS 我可以使用 list-style-type 来 div 标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18611278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use list-style-type to div tag?
提问by user2732006
I have been studying CSS. I know that we can use list-style-type
attribute to set list marker. Can we apply that attribute to a div
tag?
我一直在研究CSS。我知道我们可以使用list-style-type
属性来设置列表标记。我们可以将该属性应用于div
标签吗?
回答by Nitesh
Yes you can. The following causes a div
tag to resemble itself like a list item:
是的你可以。以下导致div
标签像列表项一样自身相似:
div {display:list-item;}
回答by Jukka K. Korpela
You can set any CSS property on any HTML element. In fact, an element always has all the CSS properties (with the defined initial value as the value, if not set). Not all properties have an effect on all elements in all circumstances, though.
您可以在任何 HTML 元素上设置任何 CSS 属性。事实上,一个元素总是拥有所有的 CSS 属性(如果没有设置,则以定义的初始值作为值)。但是,并非所有属性在所有情况下都会对所有元素产生影响。
In particular, the definition of the list-style-type
propertysays: “Applies to: elements with 'display: list-item'”. Here “applies to” means “has an effect on rendering of”.
特别是,list-style-type
属性的定义说:“适用于:具有'display:list-item'的元素”。这里的“适用于”的意思是“对渲染有影响”。
Moreover, even if you set display: list-item
on a div
, there will be no list marker (like a bullet or a number) to be seen, unless there is space on the left of the element content to accommodate it. You can arrange space using margin properties. Example:
此外,即使您设置display: list-item
了 a div
,也不会看到列表标记(如项目符号或数字),除非元素内容左侧有空间来容纳它。您可以使用边距属性来安排空间。例子:
div {
display: list-item;
margin-left: 1.3em;
list-style-type: circle;
}