首页 > 解决方案 > 自定义 ol li 缩进

问题描述

我发现了一些与此问题相关的主题,但没有一个对我有帮助。

如何修复 li 的第二行像第一行一样尊重缩进? 在此处输入图像描述

ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: my-awesome-counter;
  columns: 2;
  -webkit-columns: 2;
  -moz-columns: 2;
}

ol li {
  counter-increment: my-awesome-counter;
  margin: 1rem 0.25rem;
  line-height: normal;
}


ol li:before {
  display: inline-block;
  content: counter(my-awesome-counter);
  width: 40px;
  height: 40px;
  line-height: 24px;
  background: #000;
  border-radius: 25px;
  color: white;
  text-align: center;
  margin-right: 0.5rem;
  font-size: 24px;
  font-weight: 700;
 }

我错过了什么?

标签: htmlcss

解决方案


尝试使用position:absolute;伪元素并padding-left给予<li>

查看更新的片段:

ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: my-awesome-counter;
  /*columns: 2;
  -webkit-columns: 2;
  -moz-columns: 2;
  */
  width: 300px;
}

ol li {
  counter-increment: my-awesome-counter;
  margin: 1rem 0.25rem;
  line-height: normal;
  padding-left: 60px;
  position: relative;
}

ol li:before {
  display: inline-block;
  content: counter(my-awesome-counter);
  width: 44px;
  height: 40px;
  line-height: 24px;
  background: #000;
  border-radius: 25px;
  color: white;
  text-align: center;
  margin-right: 0.5rem;
  font-size: 24px;
  font-weight: 700;
  position: absolute;
  left: 0;
}
<ol>
  <li> test test test testtest test test testtest test test testtest test test testtest test test testtest test test test</li>
  <li> test test test testtest test test testtest test test testtest test test testtest test test testtest test test test</li>
</ol>


推荐阅读