CSS grid对齐网格项目和轨道[通俗易懂]

(21) 2023-05-05 08:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说CSS grid对齐网格项目和轨道[通俗易懂],希望能够帮助你!!!。

首先我们先将模块1关闭,模块2使用CSS网格

display: none;
      .container--2 {
        /* STARTER */
        font-family: sans-serif;
        background-color: black;
        font-size: 40px;
        margin: 100px;
        width: 1000px;
        height: 600px;
        /* CSS GRID */
        display: grid;
      }

然后我们创建一个三列两行的网格

        grid-template-columns: 125px 200px 125px;
        grid-row: 250px 100px;
CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第1张

关于对齐的一些参数

  • 水平居中对齐
justify-content: center;
CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第2张

  • 垂直居中对齐
align-content: center;
CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第3张

  • 水平平均分布(垂直平均分布同理)
justify-content: space-between;
align-content: center;

CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第4张

内部元素对齐

  • 向元素底部垂直
align-items: end;
CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第5张

  • 向元素中心对齐
align-items: end;
justify-items: center;
CSS grid对齐网格项目和轨道[通俗易懂]_https://bianchenghao6.com/blog__第6张

  • 注:(3)单独写了固定高度

单独元素对齐

  • 垂直和水平居中
align-self: center;
justify-items: center;

上一篇

已是最后文章

下一篇

已是最新文章

发表回复