Css 如何在flex设计中选择行的第一个元素和最后一个元素?

Css 如何在flex设计中选择行的第一个元素和最后一个元素?,css,flexbox,Css,Flexbox,如何从flexbox设计中选择行中的第一项和最后一项 例如,在这张照片中,一行中的第一个和最后一个: 尝试使用以下方法: div { display: flex; justify-content: space-between; } .first-row>p:first-child { color: red; } .first-row>p:last-child { color: green; }

如何从flexbox设计中选择行中的第一项和最后一项

例如,在这张照片中,一行中的第一个和最后一个:

尝试使用以下方法:

div {
      display: flex;
      justify-content: space-between;
    }
    .first-row>p:first-child {
      color: red;
    }
    .first-row>p:last-child {
      color: green;
    }

首先

第二

第三

首先

第二

第三


这里我把
当作孩子。如果需要,您可以将
div
作为子项,然后确保将flex off div应用于
第一行
第二行
,而不是
div
标记。也可以将
first row>p
更改为
first row>div

单独使用CSS包装flexbox是不可能的…我在div中动态创建元素,因此无法应用您的方法
<div class="first-row">
    <p>first</p>
    <p>second</p>
    <p>third</p>
</div>
<div class="second-row">
    <p>first</p>
    <p>second</p>
    <p>third</p>
</div>