Skip to content
On this page

布局 Layout

一个简单的自适应布局组件

基本使用

12
12
8
8
8
6
6
6
6
4
2
4
6
8
Show Code
vue
<template>
  <n-row>
    <n-col :span="12"><div class="col-box-2 col-box">12</div></n-col>
    <n-col :span="12"><div class="col-box-1 col-box">12</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="8"><div class="col-box-1 col-box">8</div></n-col>
    <n-col :span="8"><div class="col-box-2 col-box">8</div></n-col>
    <n-col :span="8"><div class="col-box-1 col-box">8</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="6"><div class="col-box-2 col-box">6</div></n-col>
    <n-col :span="6"><div class="col-box-1 col-box">6</div></n-col>
    <n-col :span="6"><div class="col-box-2 col-box">6</div></n-col>
    <n-col :span="6"><div class="col-box-1 col-box">6</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="4"><div class="col-box-1 col-box">4</div></n-col>
    <n-col :span="2"><div class="col-box-2 col-box">2</div></n-col>
    <n-col :span="4"><div class="col-box-1 col-box">4</div></n-col>
    <n-col :span="6"><div class="col-box-2 col-box">6</div></n-col>
    <n-col :span="8"><div class="col-box-1 col-box">8</div></n-col>
  </n-row>
</template>
<script setup lang="ts"></script>
<style lang="less" scoped>
.col-box {
  height: 34px;
  margin-bottom: 10px;
  text-align: center;
  line-height: 34px;
}
.col-box-1 {
  background-color: #f4d7ff;
  color: #333;
}
.col-box-2 {
  background-color: #e59fff;
  color: #fff;
}
</style>

位置偏移

通过 offset 设置偏移占用指定的列数。

10
12
8
8
2
6
6
4
2
4
6
Show Code
vue
<template>
  <n-row>
    <n-col :span="10"><div class="col-box-2 col-box">10</div></n-col>
    <n-col :span="12" :offset="2"><div class="col-box-1 col-box">12</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="8"><div class="col-box-1 col-box">8</div></n-col>
    <n-col :span="8" :offset="8"><div class="col-box-1 col-box">8</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="2"><div class="col-box-2 col-box">2</div></n-col>
    <n-col :span="6" :offset="4"><div class="col-box-1 col-box">6</div></n-col>
    <n-col :span="6" :offset="6"><div class="col-box-2 col-box">6</div></n-col>
  </n-row>
  <n-row>
    <n-col :span="4"><div class="col-box-1 col-box">4</div></n-col>
    <n-col :span="2" :offset="4"><div class="col-box-2 col-box">2</div></n-col>
    <n-col :span="4" :offset="2"><div class="col-box-1 col-box">4</div></n-col>
    <n-col :span="6" :offset="2"><div class="col-box-2 col-box">6</div></n-col>
  </n-row>
</template>

<style lang="less" scoped>
.col-box {
  height: 34px;
  margin-bottom: 10px;
  text-align: center;
  line-height: 34px;
}
.col-box-1 {
  background-color: #f4d7ff;
  color: #333;
}
.col-box-2 {
  background-color: #e59fff;
  color: #fff;
}
</style>

API

参数说明类型默认值可选值
span每行占用列数number24——
offset偏移指定列数number————

Released under the MIT License.