Skip to content
14:21
Layout

Layout

Introduction ​

The layout component implements page columns through the 24-grid system of m-row and m-col, supporting column spacing, offsets, alignment and wrapping.

Examples ​

Basic Usage ​

m-row is a horizontal row container and m-col is a column element. Use span to set the column width as a share of the 24-grid.

vue
<m-row>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
</m-row>

24 Grid ​

span ranges from 1 to 24; columns wrap automatically when the sum of spans in a row exceeds 24. When span is 0 or not set, the column width is determined by its content.

vue
<m-row>
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
	<m-col span="12"><view class="demo-block">span: 12</view></m-col>
</m-row>

Column Spacing ​

The gutter attribute sets the spacing between columns (px), and supports an array [horizontal, vertical] for the row spacing after wrapping. The column spacing is implemented with padding, so if the column content needs a background color, set it on an inner element of the Col and keep the Col itself transparent to show the gaps.

vue
<m-row gutter="20">
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
</m-row>

Offset ​

The offset attribute sets the number of offset columns to the left of a column, calculated the same way as span.

vue
<m-row>
	<m-col span="8"><view class="demo-block">span: 8</view></m-col>
	<m-col span="8" offset="8"><view class="demo-block">span: 8</view></m-col>
</m-row>

Alignment ​

The justify attribute sets the main-axis alignment, can be set to start end center space-around space-between. The default is start. The align attribute sets the cross-axis alignment, can be set to top center bottom. The default is top.

vue
<m-row justify="center">
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
</m-row>
<m-row align="bottom">
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
	<m-col span="6"><view class="demo-block">span: 6</view></m-col>
</m-row>

Wrapping ​

The wrap attribute is enabled by default, so columns wrap naturally when the sum of spans exceeds 24; disable it to keep one line.

vue
<m-row :gutter="[10, 10]">
	<m-col span="6"><view class="demo-block">1</view></m-col>
	<m-col span="6"><view class="demo-block">2</view></m-col>
	<m-col span="6"><view class="demo-block">3</view></m-col>
	<m-col span="6"><view class="demo-block">4</view></m-col>
	<m-col span="6"><view class="demo-block">5</view></m-col>
</m-row>

API ​

Row Props ​

PropDescriptionTypeDefault
gutterSpacing between columns (px), array [horizontal, vertical] for the row spacing after wrappingnumber | string | (number | string)[] | null0
justifyMain-axis alignment, can be set to start end center space-around space-betweenRowJustify | nullstart
alignCross-axis alignment, can be set to top center bottomRowAlign | nulltop
wrapWhether to wrap automaticallybooleantrue
custom-classCustom root node class namestring.ClassString-
custom-styleCustom root node inline stylestring-

Col Props ​

PropDescriptionTypeDefault
spanColumn width share, ranging from 1 to 24; width is determined by content when 0 or not setnumber | string0
offsetNumber of offset columns to the left, calculated the same way as spannumber | string | null0
custom-classCustom root node class namestring.ClassString-
custom-styleCustom root node inline stylestring-

Events ​

EventDescriptionParameters
clickEmitted when the Row is clickedevent: MouseEvent
clickEmitted when the Col is clickedevent: MouseEvent

Slots ​

NameDescription
defaultRow content (Row)
defaultCol content (Col)

Theming ​

The Layout component has no dedicated theme variables. See Theming for global variables.

Released under the MIT License.