align-items和align-content之间的区别是什么?


当前回答

我从每个回答和访问博客中学到的是

横轴和主轴是什么

主轴为水平行,横轴为垂直列-为弯曲方向:行 主轴为垂直列,横轴为水平行-为弯曲方向:列

现在是align-content和align-items

Align-content是针对行,如果容器有(多于一行) align-content的属性

.container {
  align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}

Align-items用于行中的项目 对齐项的属性

.container {
  align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}

如需更多参考,请访问flex

其他回答

主要的区别是元素的高度不一样! 然后你可以看到在一行中,它们都是中心\结束\开始

在阅读了一些答案后,他们正确地识别出,如果flex内容没有被包装,对齐内容不会产生影响。然而,他们不理解的是,当有包装内容时,对齐项仍然发挥着重要作用:

在下面的两个示例中,align-items用于将每行中的项居中,然后我们更改align-content以查看其效果。

示例1:

align-content: flex-start;

示例2:

    align-content: flex-end;

代码如下:

<div class="container">
    <div class="child" style="height: 30px;">1</div>
    <div class="child" style="height: 50px;">2</div>
    <div class="child" style="height: 60px;">3</div>
    <div class="child" style="height: 40px;">4</div>
    <div class="child" style="height: 50px;">5</div>
    <div class="child" style="height: 20px;">6</div>
    <div class="child" style="height: 90px;">7</div>
    <div class="child" style="height: 50px;">8</div>
    <div class="child" style="height: 30px;">9</div>
    <div class="child" style="height: 40px;">10</div>
    <div class="child" style="height: 30px;">11</div>
    <div class="child" style="height: 60px;">12</div>
</div>

<style>
.container {
    display: flex;
    width: 300px;
    flex-flow: row wrap;
    justify-content: space-between;
    align-items: center;
    align-content: flex-end;
    background: lightgray;
    height: 400px;
}
.child {
    padding: 12px;
    background: red;
    border: solid 1px black;
}
</style>

我从每个回答和访问博客中学到的是

横轴和主轴是什么

主轴为水平行,横轴为垂直列-为弯曲方向:行 主轴为垂直列,横轴为水平行-为弯曲方向:列

现在是align-content和align-items

Align-content是针对行,如果容器有(多于一行) align-content的属性

.container {
  align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}

Align-items用于行中的项目 对齐项的属性

.container {
  align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}

如需更多参考,请访问flex

关键属性是弹性包装。当nowrap(或当十字轴上没有多余的空间)时,align-content没有作用。当换行或反向换行时,如果十字轴中有额外的空间,它总是会产生影响(不管行数如何)。

比较以下四个方框:

根据我在这里的理解:

当您使用align-item或justify-item时,您正在分别沿列轴或行轴调整网格项中的内容。

但是: 如果使用align-content或justify-content,则是沿着列轴或行轴设置网格的位置。当你在一个更大的容器中有一个网格,宽度或高度是固定的(使用px)时,就会发生这种情况。