书山有路勤为径,学海无涯苦作舟。 知识改变命运,行动创造未来。

基础组件-Layout

Layout 布局

通过基础的 24 分栏,迅速简便地创建布局。

基础布局

通过 row 和 col 组件,并通过 col 组件的 span 属性我们就可以自由地组合布局。

<template>
  <div>
    <el-row>
      <el-col :span="24" class="grid-content">hello </el-col>
    </el-row>

    <el-row>
      <el-col :span="10" class="grid-content">test</el-col>
      <el-col :span="10" class="grid-content2">test2</el-col>
    </el-row>
  </div>

</template>

<script>
</script>

<style>
.grid-content {
  background-color: #42B983;
}

.grid-content2 {
  background-color: #ffff00;
}
</style>

实验效果

images

分栏间隔

Row 组件 提供 gutter 属性来指定每一栏之间的间隔,默认间隔为 0。

<template>
  <div>
    <el-row :gutter="50">
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
    </el-row>
  </div>

</template>

<script>
</script>

<style>
.grid-content {
  background-color: #42B983;
}

.grid-content2 {
  background-color: #ffff00;
}
</style>

实验效果

images

混合布局

通过基础的 1/24 分栏任意扩展组合形成较为复杂的混合布局。

分栏偏移

通过制定 col 组件的 offset 属性可以指定分栏偏移的栏数。

<template>
  <div>
    <el-row :gutter="50">
      <el-col :span="6" :offset="6"><div class="grid-content bg-purple">123</div></el-col>
      <!--<el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>-->
      <el-col :span="6" :offset="6"><div class="grid-content bg-purple">123</div></el-col>
    </el-row>
  </div>

</template>

<script>
</script>

<style>
.grid-content {
  background-color: #42B983;
}

.grid-content2 {
  background-color: #ffff00;
}
</style>

效果

images

对齐方式

type 属性赋值为 ‘flex’,可以启用 flex 布局,并可通过 justify 属性来指定 start, center, end, space-between, space-around 其中的值来定义子元素的排版方式。

<template>
  <div>
    <el-row type="flex" justify="space-between">
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <!--<el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>-->
      <el-col :span="6"><div class="grid-content bg-purple">123</div></el-col>
    </el-row>
  </div>

</template>

<script>
</script>

<style>
.grid-content {
  background-color: #42B983;
}

.grid-content2 {
  background-color: #ffff00;
}
</style>

实验效果

images

响应式布局

参照了 Bootstrap 的 响应式设计,预设了五个响应尺寸:xssmmdlgxl

<template>
  <div>
   <el-row :gutter="10">
     <el-col :xs="8" :sm="6" :md="4" :lg="3" :xl="1"><div class="grid-content bg-purple"></div></el-col>
     <el-col :xs="4" :sm="6" :md="8" :lg="9" :xl="11"><div class="grid-content bg-purple-light"></div></el-col>
     <el-col :xs="4" :sm="6" :md="8" :lg="9" :xl="11"><div class="grid-content bg-purple"></div></el-col>
     <el-col :xs="8" :sm="6" :md="4" :lg="3" :xl="1"><div class="grid-content bg-purple-light"></div></el-col>
   </el-row>
  </div>

</template>

<script>
</script>

<style>
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
</style>

实验效果

images