首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不计算css内容计数器的ol开始计数器

不计算css内容计数器的ol开始计数器
EN

Stack Overflow用户
提问于 2017-05-30 21:13:09
回答 2查看 337关注 0票数 1

我试图将一个列表垂直分割成两个独立的列,然后继续编号。我用的是content: counter()counter-resetcounter-increment。计数器确实从下一个数字开始,但不继续计数,而是再次重复相同的数字。

代码语言:javascript
复制
ol.rectangle-list {
  counter-reset: li;
  list-style: none;
  *list-style: decimal;
  font: 15px 'trebuchet MS', 'lucida sans';
  padding: 0;
  margin-bottom: 4em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
}

ol.rectangle-list ol {
  margin: 0 0 0 2em;
  /* Add some left margin for inner lists */
}

.rectangle-list a {
  position: relative;
  display: block;
  padding: .4em .4em .4em .8em;
  *padding: .4em;
  margin: .5em 0 .5em 2.5em;
  background: #ddd;
  color: #444;
  text-decoration: none;
  transition: all .3s ease-out;
}

.rectangle-list a:hover {
  background: #eee;
}

.rectangle-list a:before {
  content: counter(li);
  counter-increment: li;
  position: absolute;
  left: -2.5em;
  top: 50%;
  margin-top: -1em;
  background: #fa8072;
  height: 2em;
  width: 2em;
  line-height: 2em;
  text-align: center;
  font-weight: bold;
}

.rectangle-list.start-4 a:before {
  counter-reset: li 3;
  content: counter(li);
  counter-increment: li;
  position: absolute;
  left: -2.5em;
  top: 50%;
  margin-top: -1em;
  background: #fa8072;
  height: 2em;
  width: 2em;
  line-height: 2em;
  text-align: center;
  font-weight: bold;
}

.rectangle-list a:after {
  position: absolute;
  content: '';
  border: .5em solid transparent;
  left: -1em;
  top: 50%;
  margin-top: -.5em;
  transition: all .3s ease-out;
}

.rectangle-list a:hover:after {
  left: -.5em;
  border-left-color: #fa8072;
}
代码语言:javascript
复制
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
  <div class="col-xs-2">
    <ol class="rectangle-list">
      <li><a href="">1</a></li>
      <li><a href="">2</a></li>
      <li><a href="">3</a></li>
    </ol>
  </div>
  <div class="col-xs-2">
    <ol class="rectangle-list start-4">
      <li><a href="">4</a></li>
      <li><a href="">5</a></li>
      <li><a href="">6</a></li>
    </ol>
  </div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-30 21:17:42

在显示计数器的元素上有counter-reset。您需要从伪元素中删除counter-reset并将其应用于父元素。

代码语言:javascript
复制
ol.rectangle-list {
  counter-reset: li;
  list-style: none;
  *list-style: decimal;
  font: 15px 'trebuchet MS', 'lucida sans';
  padding: 0;
  margin-bottom: 4em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
}

ol.rectangle-list ol {
  margin: 0 0 0 2em;
  /* Add some left margin for inner lists */
}

.rectangle-list a {
  position: relative;
  display: block;
  padding: .4em .4em .4em .8em;
  *padding: .4em;
  margin: .5em 0 .5em 2.5em;
  background: #ddd;
  color: #444;
  text-decoration: none;
  transition: all .3s ease-out;
}

.rectangle-list a:hover {
  background: #eee;
}

.rectangle-list a:before {
  content: counter(li);
  counter-increment: li;
  position: absolute;
  left: -2.5em;
  top: 50%;
  margin-top: -1em;
  background: #fa8072;
  height: 2em;
  width: 2em;
  line-height: 2em;
  text-align: center;
  font-weight: bold;
}

.rectangle-list.start-4 a:before {
  /* counter-reset: li 3; */
  content: counter(li);
  counter-increment: li;
  position: absolute;
  left: -2.5em;
  top: 50%;
  margin-top: -1em;
  background: #fa8072;
  height: 2em;
  width: 2em;
  line-height: 2em;
  text-align: center;
  font-weight: bold;
}

.rectangle-list.start-4 {
  counter-reset: li 3;
}

.rectangle-list a:after {
  position: absolute;
  content: '';
  border: .5em solid transparent;
  left: -1em;
  top: 50%;
  margin-top: -.5em;
  transition: all .3s ease-out;
}

.rectangle-list a:hover:after {
  left: -.5em;
  border-left-color: #fa8072;
}
代码语言:javascript
复制
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
  <div class="col-xs-2">
    <ol class="rectangle-list">
      <li><a href="">1</a></li>
      <li><a href="">2</a></li>
      <li><a href="">3</a></li>
    </ol>
  </div>
  <div class="col-xs-2">
    <ol class="rectangle-list start-4">
      <li><a href="">4</a></li>
      <li><a href="">5</a></li>
      <li><a href="">6</a></li>
    </ol>
  </div>

票数 2
EN

Stack Overflow用户

发布于 2017-05-30 21:21:19

当前,您正在重置每个新元素上的计数器。因此,每次出现新的a-标记时,计数器都会再次显示相同的数字.

尝试只在ol元素处重置计数器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44271975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档