html - 项目符号和文本之间的 HTML CSS 多级列表间距
问题描述
我正在尝试创建一个多级列表,但我无法在“项目符号”和文本之间获得正确的间距。
正如您在第二张图片中看到的那样,无论“项目符号”的宽度如何,文本都向左对齐(例如,列表在 Word 中的功能)。
这是我的代码:
div {
margin: 5px 0 0 0;
padding: 0px;
font-size: 12px;
color: #777777;
}
ul,
ol,
li {
font-family: Arial, Helvetica, sans-serif !important;
font-size: 8pt;
color: #505050;
line-height: 1.4;
margin: 0 !important;
}
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;
}
ol > li {
display: table;
counter-increment: item;
padding-top: 1em;
color: #282828;
font-weight: bold;
}
ol > li:before {
content: counters(item, ".") ". ";
display: table-cell;
padding-right: 1em;
}
li ol > li {
margin: 0;
padding-top: 0.6em;
color: #505050;
font-weight: normal;
}
li ol > li:before {
content: counters(item, ".") " ";
display: table-cell;
padding-right: 1em;
}
li ol ol > li {
margin: 0;
padding-top: 0.6em;
color: #505050;
font-weight: normal;
}
li ol ol > li:before {
content: counter(item, lower-roman) ". ";
display: table-cell;
padding-right: 1em;
}
.boxl {
border-radius: 5px;
border: 1px solid #d4d4d4;
width: 735px;
height: 300px;
overflow-y: scroll;
overflow-x: hidden;
background-color: #fafafa;
}
<div class="boxl" style="padding: 0px 10px 0px 10px;">
<ol>
<li>
Heading 1
<ol>
<li>
Heading 1.1
<ol>
<li>Roman i</li>
<li>Roman ii</li>
<li>Roman iii: This is an example of a really long text to see what happens with regards to a hanging indent when the text gets carried over to the next line.</li>
</ol>
</li>
<li>Heading 1.2</li>
<li>Heading 1.3</li>
<li>Heading 1.4</li>
<li>Heading 1.5</li>
<li>Heading 1.6</li>
<li>Heading 1.7</li>
<li>Heading 1.8</li>
<li>Heading 1.9</li>
<li>Heading 1.10</li>
</ol>
</li>
<li>Heading 2</li>
</ol>
</div>
解决方案
display: table-row
在ol > li
css 中添加。像那样:
ol > li {
display: table-row;
...
}
片段:
div {
margin: 5px 0 0 0;
padding: 0px;
font-size: 12px;
color: #777777;
}
ul,
ol,
li {
font-family: Arial, Helvetica, sans-serif !important;
font-size: 8pt;
color: #505050;
line-height: 1.4;
margin: 0 !important;
}
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;
}
ol > li {
display: table-row;
counter-increment: item;
padding-top: 1em;
color: #282828;
font-weight: bold;
}
ol > li:before {
content: counters(item, ".") ". ";
display: table-cell;
padding-right: 1em;
}
li ol > li {
margin: 0;
padding-top: 0.6em;
color: #505050;
font-weight: normal;
}
li ol > li:before {
content: counters(item, ".") " ";
display: table-cell;
padding-right: 1em;
}
li ol ol > li {
margin: 0;
padding-top: 0.6em;
color: #505050;
font-weight: normal;
}
li ol ol > li:before {
content: counter(item, lower-roman) ". ";
display: table-cell;
padding-right: 1em;
}
.boxl {
border-radius: 5px;
border: 1px solid #d4d4d4;
width: 735px;
height: 300px;
overflow-y: scroll;
overflow-x: hidden;
background-color: #fafafa;
}
<div class="boxl" style="padding: 0px 10px 0px 10px;">
<ol>
<li>
Heading 1
<ol>
<li>
Heading 1.1
<ol>
<li>Roman i</li>
<li>Roman ii</li>
<li>Roman iii: This is an example of a really long text to see what happens with regards to a hanging indent when the text gets carried over to the next line.</li>
</ol>
</li>
<li>Heading 1.2</li>
<li>Heading 1.3</li>
<li>Heading 1.4</li>
<li>Heading 1.5</li>
<li>Heading 1.6</li>
<li>Heading 1.7</li>
<li>Heading 1.8</li>
<li>Heading 1.9</li>
<li>Heading 1.10</li>
</ol>
</li>
<li>Heading 2</li>
</ol>
</div>
推荐阅读
- c# - 如何刷新 Microsoft Graph 的令牌
- reactjs - 错误地加载了具有创建反应应用程序 js 块的服务工作者
- java - 如何使凌空请求队列与 Java Android 异步?
- appium - Appium 测试错误:okhttp3/ConnectionPool
- php - 如何用 fopen 编写变量名称?
- sql - Postgresql,选择输出结果+1小时
- javascript - 正则表达式在有效和无效之间交替
- angular - Angular 2 中的路由问题
- javascript - mongoose/javascript:无法更新 Mongodb 中的集合
- bash - 停止后 Cron 作业不会重新开始?