当前位置: 首页 > 文档资料 > Feui 中文文档 >

Flexbox 弹性布局

优质
小牛编辑
128浏览
2023-12-01
import { Flexbox,FlexboxItem } from 'feui';
components: {
  [Flexbox.name]: Flexbox,
  [FlexboxItem.name]: FlexboxItem
}
.flex-demo{
  text-align: center;
  color: #fff;
  background-color: #4a90e2;
  border-radius: 4px;
  background-clip: padding-box;
}

代码演示

横向排列

<flexbox>
  <flexbox-item>
    <div class="flex-demo">1</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">2</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">3</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">4</div>
  </flexbox-item>
</flexbox>

横排无空隙

<flexbox :gutter="0">
  <flexbox-item>
    <div class="flex-demo">1</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">2</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">3</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">4</div>
  </flexbox-item>
</flexbox>

垂直排列

<flexbox orient="vertical">
  <flexbox-item>
    <div class="flex-demo">1</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">2</div>
  </flexbox-item>
</flexbox>

垂直无空隙

<flexbox orient="vertical" :gutter="0">
  <flexbox-item>
    <div class="flex-demo">1</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">2</div>
  </flexbox-item>
</flexbox>

栅格系统(12列)

<flexbox>
  <flexbox-item :span="4">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">2/3</div>
  </flexbox-item>
</flexbox>

灵活网格

<flexbox>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/6">
    <div class="flex-demo">1/6</div>
  </flexbox-item>
  <flexbox-item :span="1/8">
    <div class="flex-demo">1/8</div>
  </flexbox-item>
  <flexbox-item :span="1/8">
    <div class="flex-demo">1/8</div>
  </flexbox-item>
  <flexbox-item>
    <div class="flex-demo">rest</div>
  </flexbox-item>
</flexbox>

灵活网格2

<flexbox :gutter="0">
  <flexbox-item :span="1/3" :order="4">
    <div class="flex-demo">1</div>
  </flexbox-item>
  <flexbox-item :span="1/6" :order="3">
    <div class="flex-demo">2</div>
  </flexbox-item>
  <flexbox-item :span="1/8" :order="2">
    <div class="flex-demo">3</div>
  </flexbox-item>
  <flexbox-item :span="1/8" :order="1">
    <div class="flex-demo">4</div>
  </flexbox-item>
  <flexbox-item :order="-99">
    <div class="flex-demo">5</div>
  </flexbox-item>
</flexbox>

溢出换行

<flexbox :gutter="0" wrap="wrap">
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
  </flexbox-item>
  <flexbox-item :span="1/3">
    <div class="flex-demo">1/3</div>
    </flexbox-item>
</flexbox>

API

参数说明类型默认值可选值
gutter间隙像素大小(px)Number8-
orient排列方向Stringhorizontalhorizontal,vertical
justifyflex的justify-content属性String--
alignflex的align-items属性String--
wrapflex的flex-wrap属性String--
directionflex的flex-direction属性String--
-----

Slots

Slot名说明备注
defaultflexbox-item的内容插槽-
---

FlexboxItem

API

参数说明类型默认值可选值
span占用宽度,如果不设置,所有flexbox-item将平分Number8-
orderflex的order属性String8-
-----

Slots

Slot名说明备注
default内容插槽-
---