我有一个CSS网格。我想使用nth-child
odd
和even
选择器来使项目被推到网格的每个垂直边缘-它应该看起来像:
.questionsAndAnswers {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 24px;
font-size: 12px;
font-family: "sans-serif";
justify-items: end;
border: 1px solid red;
}
.questionsAndAnswers:nth-child(odd){
justify-items: start;
}
<div class="questionsAndAnswers">
<p>
one
</p>
<p>
two
</p>
<p>
three
</p>
<p>
four
</p>
</div>
3条答案
按热度按时间qgzx9mmu1#
你接近了-在子
<p>
-元素上使用nth-child
伪选择器,并使用justify-self
代替justify-items
。30byixjq2#
.questionsAndAnswers
{
}
.questionsAndAnswers p:nth-child(1)
{
}
.questionsAndAnswers p:nth-child(2)
{
}
.questionsAndAnswers p:nth-child(3)
{
}
.questionsAndAnswers p:nth-child(4)
{
}
gmxoilav3#