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 图像都在彼此之上

javascript - 如何使用数据元素的值作为选择器 jquery

html - 为什么这个 flexbox 页脚不能在移动设备上工作?

php - 如何在 SQL 语句中使用 PHP 变量

html - 使导航全高

html - 将鼠标悬停在子菜单上时,如何使导航菜单链接颜色仍然悬停?

html - 表格溢出在 Chrome 和 IE 中有效,但在 Firefox 中无效

html - 对齐 : Bottom to top

每侧带有文本的 HTML slider

javascript - 在点击事件 html 的新窗口中打开图像