Layout佈局

Layout 佈局

經過基礎的 24 分欄,迅速簡便地建立佈局。css

基礎佈局

使用單一分欄建立基礎的柵格佈局。html

 

 

經過 row 和 col 組件,並經過 col 組件的 span 屬性咱們就能夠自由地組合佈局。element-ui

<el-row> <el-col :span="24"><div class="grid-content bg-purple-dark"></div></el-col> </el-row> <el-row> <el-col :span="12"><div class="grid-content bg-purple"></div></el-col> <el-col :span="12"><div class="grid-content bg-purple-light"></div></el-col> </el-row> <el-row> <el-col :span="8"><div class="grid-content bg-purple"></div></el-col> <el-col :span="8"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="8"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> </el-row> <el-row> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple-light"></div></el-col> </el-row> <style> .el-row { margin-bottom: 20px; &:last-child { margin-bottom: 0; } } .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; } .row-bg { padding: 10px 0; background-color: #f9fafc; } </style> 
 

分欄間隔

分欄之間存在間隔。瀏覽器

 

 

Row 組件 提供 gutter 屬性來指定每一欄之間的間隔,默認間隔爲 0。佈局

<el-row :gutter="20"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <style> .el-row { margin-bottom: 20px; &:last-child { margin-bottom: 0; } } .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; } .row-bg { padding: 10px 0; background-color: #f9fafc; } </style> 
 

混合佈局

經過基礎的 1/24 分欄任意擴展組合造成較爲複雜的混合佈局。flex

 

 

<el-row :gutter="20"> <el-col :span="16"><div class="grid-content bg-purple"></div></el-col> <el-col :span="8"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row :gutter="20"> <el-col :span="8"><div class="grid-content bg-purple"></div></el-col> <el-col :span="8"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row :gutter="20"> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> <el-col :span="16"><div class="grid-content bg-purple"></div></el-col> <el-col :span="4"><div class="grid-content bg-purple"></div></el-col> </el-row> <style> .el-row { margin-bottom: 20px; &:last-child { margin-bottom: 0; } } .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; } .row-bg { padding: 10px 0; background-color: #f9fafc; } </style> 
 

分欄偏移

支持偏移指定的欄數。ui

 

 

經過制定 col 組件的 offset 屬性能夠指定分欄偏移的欄數。spa

<el-row :gutter="20"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6" :offset="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row :gutter="20"> <el-col :span="6" :offset="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6" :offset="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row :gutter="20"> <el-col :span="12" :offset="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <style> .el-row { margin-bottom: 20px; &:last-child { margin-bottom: 0; } } .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; } .row-bg { padding: 10px 0; background-color: #f9fafc; } </style> 
 

對齊方式

經過 flex 佈局來對分欄進行靈活的對齊。設計

 

 

將 type 屬性賦值爲 'flex',能夠啓用 flex 佈局,並可經過 justify 屬性來指定 start, center, end, space-between, space-around 其中的值來定義子元素的排版方式。3d

<el-row type="flex" class="row-bg"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="center"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="end"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-between"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <el-row type="flex" class="row-bg" justify="space-around"> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple-light"></div></el-col> <el-col :span="6"><div class="grid-content bg-purple"></div></el-col> </el-row> <style> .el-row { margin-bottom: 20px; &:last-child { margin-bottom: 0; } } .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; } .row-bg { padding: 10px 0; background-color: #f9fafc; } </style> 
 

響應式佈局

參照了 Bootstrap 的 響應式設計,預設了五個響應尺寸:xssmmdlg 和 xl

 

 

<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> <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> 
 

基於斷點的隱藏類

Element 額外提供了一系列類名,用於在某些條件下隱藏元素。這些類名能夠添加在任何 DOM 元素或自定義組件上。若是須要,請自行引入如下文件:

import 'element-ui/lib/theme-chalk/display.css'; 

包含的類名及其含義爲:

  • hidden-xs-only - 當視口在 xs 尺寸時隱藏
  • hidden-sm-only - 當視口在 sm 尺寸時隱藏
  • hidden-sm-and-down - 當視口在 sm 及如下尺寸時隱藏
  • hidden-sm-and-up - 當視口在 sm 及以上尺寸時隱藏
  • hidden-md-only - 當視口在 md 尺寸時隱藏
  • hidden-md-and-down - 當視口在 md 及如下尺寸時隱藏
  • hidden-md-and-up - 當視口在 md 及以上尺寸時隱藏
  • hidden-lg-only - 當視口在 lg 尺寸時隱藏
  • hidden-lg-and-down - 當視口在 lg 及如下尺寸時隱藏
  • hidden-lg-and-up - 當視口在 lg 及以上尺寸時隱藏
  • hidden-xl-only - 當視口在 xl 尺寸時隱藏

Row Attributes

參數 說明 類型 可選值 默認值
gutter 柵格間隔 number 0
type 佈局模式,可選 flex,現代瀏覽器下有效 string
justify flex 佈局下的水平排列方式 string start/end/center/space-around/space-between start
align flex 佈局下的垂直排列方式 string top/middle/bottom top
tag 自定義元素標籤 string * div

Col Attributes

參數 說明 類型 可選值 默認值
span 柵格佔據的列數 number 24
offset 柵格左側的間隔格數 number 0
push 柵格向右移動格數 number 0
pull 柵格向左移動格數 number 0
xs <768px 響應式柵格數或者柵格屬性對象 number/object (例如: {span: 4, offset: 4})
sm ≥768px 響應式柵格數或者柵格屬性對象 number/object (例如: {span: 4, offset: 4})
md ≥992px 響應式柵格數或者柵格屬性對象 number/object (例如: {span: 4, offset: 4})
lg ≥1200px 響應式柵格數或者柵格屬性對象 number/object (例如: {span: 4, offset: 4})
xl ≥1920px 響應式柵格數或者柵格屬性對象 number/object (例如: {span: 4, offset: 4})
tag 自定義元素標籤 string * div
相關文章
相關標籤/搜索