仅在子元素为<strong>时更改<li>吗?

时间:2019-04-05 13:06:05

标签: html css css3

我有这个ul,所有不活跃的li都有一个跨度,但是活跃的li有一个强大的!我的问题是,如果纯属SCSS的孩子坚强,是否有可能改变li的背景颜色!

li {
  margin-left: 3px;
  margin-bottom: 3px;
  border: solid transparent;
  background-color: #fff;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  color: #004f5b;
  font-size: 24px;
  font-weight: 900;
  color: #004f5b;
  box-sizing: border-box;
  padding: 6px 68px;
  /*this only adds the background over the strong but not the whole li*/
  &>strong {
    background-color: red;
  }
}
<ul>
  <li>
    <span>1</span>
  </li>
  <li>
    <strong>2</strong>
  </li>
  <li>
    <span>3</span>
  </li>
  <li>
    <span>4</span>
  </li>
  <li>
    <span>5</span>
  </li>
  <li>
    <span>6</span>
  </li>
  <li>
    <span>7</span>
  </li>
</ul>

1 个答案:

答案 0 :(得分:-3)

您只需要这样做:

li {
  margin-left: 3px;
  margin-bottom: 3px;
  border: solid transparent;
  background-color: #fff;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  color: #004f5b;
  font-size: 24px;
  font-weight: 900;
  color: #004f5b;
  box-sizing: border-box;
  padding: 6px 68px;
  /*this only adds the background over the strong but not the whole li*/
  strong {
    background-color: red;
  }
}

没有“&>”