2

我想在悬停时更改列表的内容,即罗马更改为数字 1、2、3

我试过li:hover li:hover:after了,但两者都会用现有内容添加内容

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

.cc1 {
  background-color: #FF6766;
  color: #FFF;
}
 <ul class="scheme">
      <li class="cc1" ></li>
     <li class="cc1" ></li>
     <li class="cc1" ></li>
</ul>

4

2 回答 2

3

使用这个选择器:

li:hover:before {
    content: counter(chrome-counter, decimal);
}

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, decimal);
}

.cc1 {
  background-color: #FF6766;
  color: #FFF;
}
<ul class="scheme">
      <li class="cc1" ></li>
     <li class="cc1" ></li>
     <li class="cc1" ></li>
</ul>

于 2014-10-18T06:24:02.327 回答
3

如果您正在处理 :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>

于 2014-10-18T06:24:18.100 回答