Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将ol列表编号排列到左侧_Html_Css_Html Lists - Fatal编程技术网

Html 将ol列表编号排列到左侧

Html 将ol列表编号排列到左侧,html,css,html-lists,Html,Css,Html Lists,是否可以将ol列表编号(两位数)从左侧开始排列 通常是这样的 1 2 . . 10 12 但我需要这样的表现 1 2 . . 10 12 您可以使用CSS计数器: CSS: ol { padding-left: 40px; list-style: none; counter-reset: number; } ol li:before { display: inline-block; content: counter(number) '.';

是否可以将ol列表编号(两位数)从左侧开始排列

通常是这样的

1
2
.
.
10
12
但我需要这样的表现

1
2
.
.
10
12

您可以使用CSS计数器:

CSS

ol {
    padding-left: 40px;
    list-style: none;
    counter-reset: number;
}

ol li:before {
    display: inline-block;

    content: counter(number) '.';
    counter-increment: number;

    width: 30px;
}
这种方法唯一的问题是数字区域的宽度是固定的,因此它不会随着元素数量的增加而扩展


演示:

可能是您可以使用计数器-增量进行此操作。这样写:

ul{    counter-reset: chapter 0;  }
li:before{    
    counter-increment: chapter;    
    content:counter(chapter) ". ";
    width:20px;
    display: inline-block;
    text-align: right;   
}  

勾选此项

您能澄清您的问题吗?默认情况下,数字向右浮动:。计数器对CSS3来说并不陌生。@BoltClock:嗯,我一直以为它们是。谢谢你的提示!