基于 Flex 的简易布局代码

发布于 2023-09-03 08:51:39 字数 3266 浏览 32 评论 0

使用方法:

      <div class="flex-row" >
        <div class="flex-1 justify-center align-center">
          ww
        </div>
        <div class="flex-1">
          weeeeeeeee
        </div>
        <div class="flex-3">
          nnnnnnnnnnnnnnnnn
        </div>

        <div class="flex-3">
          <div class="flex-column">
            <div class="flex-1">
              <div class="">
                bbbbbbbbbbbbbbbbb
              </div>
            </div>
            <div class="flex-1">
              bbbbbbbbbbbbb
            </div>
          </div>
        </div>
      </div>

配合 normalize.css 使用更佳

stylus 或 sass 代码:

.flex-row
  display: flex
  flex-direction: row
  flex-wrap: wrap
.flex-row-reverse
  display: flex
  flex-direction: row-reverse
  flex-wrap: wrap
.flex-column
  display: flex
  flex-direction: column
  flex-wrap: wrap
.flex-column-reverse
  display: flex
  flex-direction: column-reverse
  flex-wrap: wrap
.flex-1
  display: flex
  flex: 1
.flex-2
  display: flex
  flex: 2
.flex-3
  display: flex
  flex: 3
.flex-4
  display: flex
  flex: 4
.flex-5
  display: flex
  flex: 5
.flex-6
  display: flex
  flex: 6
.flex-7
  display: flex
  flex: 7
.flex-8
  display: flex
  flex: 8
.flex-9
  display: flex
  flex: 9
.flex-10
  display: flex
  flex: 10
.flex-11
  display: flex
  flex: 11
.justify-flex-start
  justify-content: flex-start
.justify-flex-end
  justify-content: flex-end
.justify-center
  justify-content: center
.justify-space-between
  justify-content: space-between
.justify-space-around
  justify-content: space-around
.align-flex-start
  align-items: flex-start
.align-flex-end
  align-items: flex-end
.align-center
  align-items: center
.align-baseline
  align-items: baseline
.align-stretch
  align-items: stretch

CSS 代码:

.flex-row {
  flex: 1;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.flex-row-reverse {
  flex: 1;
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: wrap;
}
.flex-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}
.flex-column-reverse {
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  flex-wrap: wrap;
}
.flex-1 {
  display: flex;
  flex: 1;
}
.flex-2 {
  display: flex;
  flex: 2;
}
.flex-3 {
  display: flex;
  flex: 3;
}
.flex-4 {
  display: flex;
  flex: 4;
}
.flex-5 {
  display: flex;
  flex: 5;
}
.flex-6 {
  display: flex;
  flex: 6;
}
.flex-7 {
  display: flex;
  flex: 7;
}
.flex-8 {
  display: flex;
  flex: 8;
}
.flex-9 {
  display: flex;
  flex: 9;
}
.flex-10 {
  display: flex;
  flex: 10;
}
.flex-11 {
  display: flex;
  flex: 11;
}
.justify-flex-start {
  justify-content: flex-start;
}
.justify-flex-end {
  justify-content: flex-end;
}
.justify-center {
  justify-content: center;
}
.justify-space-between {
  justify-content: space-between;
}
.justify-space-around {
  justify-content: space-around;
}
.align-flex-start {
  align-items: flex-start;
}
.align-flex-end {
  align-items: flex-end;
}
.align-center {
  align-items: center;
}
.align-baseline {
  align-items: baseline;
}
.align-stretch {
  align-items: stretch;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

岁月无声

暂无简介

文章
评论
28 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文