如果您正在处理 :before 伪元素,则需要将所有状态应用于该确切元素......所以不是主元素,也不是 :after 元素,而是需要更改的元素,即li:before
在你的情况下:
ul {
min-height: 30px;
width: 180px;
margin-left:-30px;
list-style-type: none;
counter-reset: chrome-counter;
}
li:before {
content: counter(chrome-counter, lower-roman);
padding: 1px 2px;
margin-right: 0.2em;
font-weight: bold;
}
li {
margin: 2px 0;
padding: 1px 4px;
font: normal bold 18px/32px ms-sans, geneva, sans-serif;
display: inline-block;
width: 40px;
text-align: center;
color: #FFF;
counter-increment: chrome-counter;
}
li:hover {
padding: 4px 8px;
color: #333;
/*content : '..';*/
counter-reset : counter(chrome-counter, upper-roman);
box-shadow: 0px 0px 4px #222;
border-radius: 1.5em .5em / 2.5em 2em;
}
li:hover:before {
content: counter(chrome-counter, upper-roman);
padding: 1px 2px;
margin-right: 0.2em;
font-weight: bold;
}
.cc1 {
background-color: #FF6766;
color: #FFF;
}
<ul class="scheme">
<li class="cc1" ></li>
<li class="cc1" ></li>
<li class="cc1" ></li>
</ul>
这是一个更改为您在评论中要求的 HTML 内容的示例:
ul {
min-height: 30px;
width: 180px;
margin-left:-30px;
list-style-type: none;
counter-reset: chrome-counter;
}
li:before {
content: counter(chrome-counter, lower-roman);
padding: 1px 2px;
margin-right: 0.2em;
font-weight: bold;
}
li {
margin: 2px 0;
padding: 1px 4px;
font: normal bold 18px/32px ms-sans, geneva, sans-serif;
display: inline-block;
width: 40px;
text-align: center;
color: #FFF;
counter-increment: chrome-counter;
}
li:hover {
padding: 4px 8px;
color: #333;
/*content : '..';*/
counter-reset : counter(chrome-counter, upper-roman);
box-shadow: 0px 0px 4px #222;
border-radius: 1.5em .5em / 2.5em 2em;
}
li:hover:before {
content: "";
padding: 1px 2px;
margin-right: 0.2em;
font-weight: bold;
}
li span {display: none}
li:hover span {display: initial}
.cc1 {
background-color: #FF6766;
color: #FFF;
}
<ul class="scheme">
<li class="cc1" ><span>#</span></li>
<li class="cc1" ><span>0</span></li>
<li class="cc1" ><span>*</span></li>
</ul>