2017-05-30 70 views
2

我試圖將一個列表分成2個獨立的列垂直均勻,並繼續編號。我正在使用content: counter()counter-resetcounter-increment。計數器確實從下一個數字開始計數,但不會繼續計數,但會再次重複相同的數字。ol開始計數器與css內容計數器不計數

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

回答

3

你有你顯示計數器的元素有關的counter-reset。您需要從僞元素中移除counter-reset,然後將其應用於父代。

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

0

目前,要重設每一個新的一個元素在櫃檯上。因此,每當出現新的a標籤時,計數器將再次顯示相同的編號。

嘗試僅在ol元素處重置計數器。