ker*_*cht 241 html css html-lists
我希望有一个"内部"列表,列表项目符号或十进制数字都与高级文本块齐平.第二行列表条目必须与第一行具有相同的缩进!
例如:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor. Aenean Aenean massa.
Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus. Donec quam felis,
1. Text
2. Text
3. longer Text, longer Text, longer Text, longer Text, longer Text, longer Text
second line of longer Text
4. Text
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor.
Run Code Online (Sandbox Code Playgroud)
CSS为其"list-style-position"提供了两个值 - 内部和外部.使用"内部"第二行与列表点齐平,而不是使用上级行:
3. longer Text, longer Text, longer Text, longer Text, longer Text, longer Text
second line of longer Text
4. Text
Run Code Online (Sandbox Code Playgroud)
我的列表中的"外部"宽度不再与高级文本块齐平.
实验宽度text-indent,padding-left和margin-left适用于无序列表,但它们对于有序列表失败,因为它取决于list-decimal的字符数:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor.
3. longer Text, longer Text, longer Text, longer Text, longer Text, longer Text
second line of longer Text
4. Text
11. Text
12. Text
Run Code Online (Sandbox Code Playgroud)
"11." 和"12." 与"3"相比,不优于文本块.和"4.".
那么关于有序列表和二线缩进的秘密在哪里?谢谢你的努力!
use*_*621 252
这个答案已经过时了.你可以更简单地做到这一点,正如我所指出的那样,我很惊讶地发现这还没有解决.您可以使用浏览器的表格布局算法(不使用表格),如下所示:
ul {
list-style-position: outside;
}
Run Code Online (Sandbox Code Playgroud)
请参阅https://www.w3schools.com/cssref/pr_list-style-position.asp
ol {
counter-reset: foo;
display: table;
}
ol > li {
counter-increment: foo;
display: table-row;
}
ol > li::before {
content: counter(foo) ".";
display: table-cell; /* aha! */
text-align: right;
}
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/4rnNK/1/
要使其在IE8中工作,请使用:before
带有一个冒号的旧表示法.
小智 205
我相信这会做你想要的.
.cssClass li {
list-style-type: disc;
list-style-position: inside;
text-indent: -1em;
padding-left: 1em;
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle:https://jsfiddle.net/dzbos70f/
Chu*_*utt 36
没有任何黑客攻击的最简单,最干净的方法就是缩进ul
(或ol
),如下:
ol {
padding-left: 40px;
list-style-position: outside; // Only necessary if you've set it to "inside" elsewhere
}
Run Code Online (Sandbox Code Playgroud)
这给出了与接受的答案相同的结果:https://jsfiddle.net/af2fqryz/
截图:
小智 24
检查这个小提琴:
它显示了如何使用CSS手动缩进ul和ol.
HTML
<head>
<title>Lines</title>
</head>
<body>
<ol type="1" style="list-style-position:inside;">
<li>Text</li>
<li>Text</li>
<li >longer Text, longer Text, longer Text, longer Text second line of longer Text </li>
</ol>
<br/>
<ul>
<li>Text</li>
<li>Text</li>
<li>longer Text, longer Text, longer Text, longer Text second line of longer Text </li>
</ul>
</body>
Run Code Online (Sandbox Code Playgroud)
CSS
ol
{
margin:0px;
padding-left:15px;
}
ol li
{
margin: 0px;
padding: 0px;
text-indent: -1em;
margin-left: 1em;
}
ul
{
margin:0;
padding-left:30px;
}
ul li
{
margin: 0px;
padding: 0px;
text-indent: 0.5em;
margin-left: -0.5em;
}
Run Code Online (Sandbox Code Playgroud)
我也编辑了你的小提琴
记下它.
您可以设置一个ol
或ul
在CSS中的边距和填充
ol {
margin-left: 0;
padding-left: 3em;
list-style-position: outside;
}
Run Code Online (Sandbox Code Playgroud)
我相信你只需将列表'bullet'放在填充之外.
li {
list-style-position: outside;
padding-left: 1em;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用CSS选择范围;在这种情况下,您需要列出项目1-9:
ol li:nth-child(n+1):nth-child(-n+9)
Run Code Online (Sandbox Code Playgroud)
然后适当调整这些第一项的边距:
ol li:nth-child(n+1):nth-child(-n+9) { margin-left: .55em; }
ol li:nth-child(n+1):nth-child(-n+9) em,
ol li:nth-child(n+1):nth-child(-n+9) span { margin-left: 19px; }
Run Code Online (Sandbox Code Playgroud)
在此处查看其运行情况:http : //www.wortfm.org/wort-madison-charts-for-the-week-beginning-11192012/
我的解决方案与Pumbaa80的解决方案完全相同,但我建议使用display: table
代替display:table-row
forli
元素。所以它会是这样的:
ol {
counter-reset: foo; /* default display:list-item */
}
ol > li {
counter-increment: foo;
display: table; /* instead of table-row */
}
ol > li::before {
content: counter(foo) ".";
display: table-cell;
text-align: right;
}
Run Code Online (Sandbox Code Playgroud)
所以现在我们可以在li
's之间使用边距
下面的 CSS 做到了这一点:
ul {
margin-left: 1em;
}
li {
list-style-position: outside;
padding-left: 0.5em;
}
Run Code Online (Sandbox Code Playgroud)