Html 第n个孩子(偶数)没有';我不工作,但做些零工

Html 第n个孩子(偶数)没有';我不工作,但做些零工,html,css,Html,Css,我想为.st--player box添加一个css,使偶数具有值float:right,奇数有一个浮点:左 <div class="st--players-container"> <a href="#"> <div class="st--player-box">...</div> </a> <a href="#"> <

我想为
.st--player box
添加一个css,使偶数具有值
float:right,奇数有一个
浮点:左

<div class="st--players-container">
        <a href="#">
            <div class="st--player-box">...</div>
        </a>
            <a href="#">
            <div class="st--player-box">...</div>
        </a>
            <a href="#">
            <div class="st--player-box">...</div>
        </a>
            <a href="#">
            <div class="st--player-box">...</div>
        </a>
</div>
因为
div.st--player框
不是
div.st--player容器
的根子级。您需要将根子元素

作为目标,所有
都是其
中的第一个子元素,因此它们都是奇数子元素。您的意思是
.st--players容器>a:n个子项(奇数)>.st--player框
?是的,将第n个子项添加到标记中
.st--players-container .st--player-box {
  display: block;
  width: -webkit-calc(47%);
  border: 1px solid #dadada;
  box-sizing: border-box;
  margin: 0 5px 10px 5px;
  overflow: hidden;
}
.st--players-container .st--player-box:nth-child(odd) {
  float: left;
}
.st--players-container .st--player-box:nth-child(even) {
  float: right;
}
.st--players-container .st--player-box {
  display: block;
  width: -webkit-calc(47%);
  border: 1px solid #dadada;
  box-sizing: border-box;
  margin: 0 5px 10px 5px;
  overflow: hidden;
}
.st--players-container a:nth-child(odd) {
  float: left;
}
.st--players-container a:nth-child(even) {
  float: right;
}