首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >flexbox指南(不支持display: flex时)

flexbox指南(不支持display: flex时)

作者头像
用户7293182
发布2022-01-20 18:05:29
发布2022-01-20 18:05:29
69000
代码可运行
举报
文章被收录于专栏:jQuery每日经典jQuery每日经典
运行总次数:0
代码可运行

|| 原文地址:https://kyusuf.com/post/almost-complete-guide-to-flexbox-without-flexbox/

不幸的是,并不是每个人都有能够查看flexbox布局的浏览器/设备。这是一个cheatsheet风格的指南,提供了flexbox属性的向后兼容替代方案。

虽然本指南中的一些CSS看起来很明显,但我希望挑战flexbox的使用,并提供一些简单的解决方案来解决在它流行之前就存在的问题。

flex-direction

row

Displays items horizontally

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
}

row-reverse

Displays items horizontally in reverse order

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  direction: rtl;
}

.item {
  display: inline-block;
}

column

Displays items vertically

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: block;
}

column-reverse

Displays items vertically in reverse order

代码语言:javascript
代码运行次数:0
运行
复制
.container, .item {
  transform: scaleY(-1);
}

.item {
  display: block;
}

Credit: Vincent Valentin

flex-wrap

nowrap

Squishes items to stop wrapping

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
}

wrap

Wraps items when altogether wider than container

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
}

wrap-reverse

Wraps items in reverse order when altogether wider than container

代码语言:javascript
代码运行次数:0
运行
复制
.container, .item {
  transform: scaleY(-1);
}

.item {
  display: inline-block;
}

justify-content

flex-start

Horizontally aligns items to start of container

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
}

flex-end

Horizontally aligns items to end of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  text-align: right;
}

.item {
  display: inline-block;
}

center

Horizontally aligns items to center of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  text-align: center;
}

.item {
  display: inline-block;
}

space-between

Spaces items between start and end of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  text-align: justify;
}

.container:after {
  content: '';
  display: inline-block;
  width: 100%;
}

.item {
  display: inline-block;
}

Note: This method only works with uncompressed HTML and requires a fixed height on the container

space-around

Spaces items with equidistant space

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
  text-align: center;
}

align-items

flex-start

Vertically aligns items to start of container

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
}

flex-end

Vertically aligns items to end of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
  vertical-align: bottom;
}

center

Vertically aligns items to center of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
  vertical-align: middle;
}

stretch

Vertically stretches items from start to end of container

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
  height: 100%;
}

align-content

flex-start

Vertically aligns items to start of container

代码语言:javascript
代码运行次数:0
运行
复制
.item {
  display: inline-block;
}

flex-end

Vertically aligns items to end of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table-cell;
  vertical-align: bottom;
}

.item {
  display: inline-block;
}

center

Vertically aligns items to center of container

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table-cell;
  vertical-align: middle;
}

.item {
  display: inline-block;
}

flex items

flex-grow

Grows an item to fill remaining space

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
}

.item.grow {
  width: 100%;
}

flex-shrink

Shrinks an item and other items fill remaining space

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
}

.item.shrink {
  width: 1px;
}

align-self

Shrinks an item and other items fill remaining space

代码语言:javascript
代码运行次数:0
运行
复制
.container {
  display: table;
}

.item {
  display: table-cell;
}

.item.bottom {
  vertical-align: bottom;
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-07-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 jQuery每日经典 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • flex-direction
    • row
    • row-reverse
    • column
    • column-reverse
  • flex-wrap
    • nowrap
    • wrap
    • wrap-reverse
  • justify-content
    • flex-start
    • flex-end
    • center
    • space-between
    • space-around
  • align-items
    • flex-start
    • flex-end
    • center
    • stretch
  • align-content
    • flex-start
    • flex-end
    • center
  • flex items
    • flex-grow
    • flex-shrink
    • align-self
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档