html – 更改备用元素css的背景颜色

前端之家收集整理的这篇文章主要介绍了html – 更改备用元素css的背景颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想改变替代元素的颜色,但我的代码不起作用.我的代码更改了整个容器元素的颜色.

任何人都可以告诉我在代码中哪里出错?

.pvt-msg-panel {
  height: 92vh;
  float: left;
  margin-top: -20px;
}
#pvt-messages-Box {
  height: 50vh;
  width: 650px;
  margin-top: 10px;
  margin-left: 10px;
  overflow-y: scroll;
}
.pvt-messages-Box-item {
  padding: 10px;
  padding-left: 20px;
  position: relative;
  display: inline-block;
  width: 100%;
  color: black;
  padding-left: 20px;
  font-size: 12px;
  cursor: pointer;
}
.pvt-messages-Box-item:nth-child(odd) {
  background-color: green;
}
.pvt-messages-Box-item:nth-child(even) {
  background-color: white;
}
Box"> Box-item">Box-item">Box-item">
最佳答案
使用第一个子选择器时,br标签将尝试选择偶数选择器.尝试使用nth-of-type选择器然后你去!

看看这个,让我知道你的反馈.谢谢!

.pvt-msg-panel{
  height: 92vh;
  float: left;
  margin-top: -20px;
}
#pvt-messages-Box{
  height: 50vh;
  width: 650px;
  margin-top: 10px;
  margin-left: 10px;
  overflow-y: scroll;
}
.pvt-messages-Box-item{
  padding:10px;
  padding-left: 20px;
  position: relative;
  display: inline-block;
  width: 100%;
  color: black;
  padding-left: 20px;
  font-size: 12px;
  cursor: pointer;
}

.pvt-messages-Box-item:nth-of-type(odd){
  background-color: green;
}
.pvt-messages-Box-item:nth-of-type(even){
  background-color: white;
}
Box"> Box-item">Box-item">Box-item">
@H_502_33@ 原文链接:https://www.f2er.com/css/427663.html

猜你在找的CSS相关文章