html - 自定义 ol li 缩进

标签 html css

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

如何修复 li 的第二行与第一行一样的缩进? enter image description here

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;
 }

我错过了什么?

最佳答案

尝试使用 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>

关于html - 自定义 ol li 缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847458/

相关文章:

html - 问题照片上的文字并使其响应

css - 如何清除这些样式

html - 悬停时会淡入图像的纯色

html - 将 td 元素中的按钮右对齐

UITextView 中带有 <blockquote> 标签的 HTML

javascript - 使用 setTimeout 让弹出窗口自行淡出

html - 双倍行距元素符号列表

html - div元素中额外空间的解决方案

javascript - 使用javascript在图像上覆盖网格,需要帮助获取网格坐标

html - 需要帮助将 JS 代码结果/返回放入 div