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

时间:2019-06-06 00:54:38

标签: css flexbox

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

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

sample

1 个答案:

答案 0 :(得分:0)

尝试使用此:

div {
      display: flex;
      justify-content: space-between;
    }
    .first-row>p:first-child {
      color: red;
    }
    .first-row>p:last-child {
      color: green;
    }
<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>

在这里,我以<p>为孩子。如果愿意,可以将div作为孩子,然后确保从div移除flex并应用于first-rowsecond-row而不是div标签。并将first-row>p更改为first-row>div