JGuang

Grid

Grid · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Grid

24 Grids System.

Design concept

<div class="grid-demo"> <img draggable="false" src="https://gw.alipayobjects.com/zos/bmw-prod/9189c9ef-c601-40dc-9960-c11dbb681888.svg" alt="grid design" /> </div>

In most business situations, Ant Design needs to solve a lot of information storage problems within the design area, so based on 12 Grids System, we divided the design area into 24 sections.

We name the divided area 'box'. We suggest four boxes for horizontal arrangement at most, one at least. Boxes are proportional to the entire screen as shown in the picture above. To ensure a high level of visual comfort, we customize the typography inside of the box based on the box unit.

Outline

In the grid system, we define the frame outside the information area based on row and column, to ensure that every area can have stable arrangement.

Following is a brief look at how it works:

  • Establish a set of column in the horizontal space defined by row (abbreviated col).
  • Your content elements should be placed directly in the col, and only col should be placed directly in row.
  • The column grid system is a value of 1-24 to represent its range spans. For example, three columns of equal width can be created by <Col span={8} />.
  • If the sum of col spans in a row are more than 24, then the overflowing col as a whole will start a new line arrangement.

Our grid systems base on Flex layout to allow the elements within the parent to be aligned horizontally - left, center, right, wide arrangement, and decentralized arrangement. The Grid system also supports vertical alignment - top aligned, vertically centered, bottom-aligned. You can also define the order of elements by using order.

Layout uses a 24 grid layout to define the width of each "box", but does not rigidly adhere to the grid layout.

Examples

  • Basic Grid · basic
  • Grid Gutter · gutter
  • Column offset · offset
  • Grid sort · sort
  • Typesetting · flex
  • Alignment · flex-align
  • Order · flex-order
  • Flex Stretch · flex-stretch
  • Responsive · responsive
  • Flex Responsive · responsive-flex
  • More responsive · responsive-more
  • Playground · playground
  • useBreakpoint Hook · useBreakpoint

API

Common props ref:Common props

If the Ant Design grid layout component does not meet your needs, you can use the excellent layout components of the community:

Row

PropertyDescriptionTypeDefaultVersionGlobal Config
alignVertical alignmenttop | middle | bottom | stretch | {[key in 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl']: 'top' | 'middle' | 'bottom' | 'stretch'}topobject: 4.24.0×
gutterSpacing between grids, could be a string CSS units or a object like { xs: 8, sm: 16, md: 24}. Or you can use array to make horizontal and vertical spacing work at the same time [horizontal, vertical]number | string | object | array0string: 5.28.0×
justifyHorizontal arrangementstart | end | center | space-around | space-between | space-evenly | {[key in 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl']: 'start' | 'end' | 'center' | 'space-around' | 'space-between' | 'space-evenly'}startobject: 4.24.0×
wrapAuto wrap linebooleantrue4.8.0×

Col

PropertyDescriptionTypeDefaultVersionGlobal Config
flexFlex layout style. Number for 'flex: n n auto', string is applied directly (e.g. pure number string 'n' for 'flex: n 1 0')string | number-×
offsetThe number of cells to offset Col from the leftnumber0×
orderRaster ordernumber0×
pullThe number of cells that raster is moved to the leftnumber0×
pushThe number of cells that raster is moved to the rightnumber0×
spanRaster number of cells to occupy, 0 corresponds to display: nonenumber-×
xsscreen < 576px and also default setting, could be a span value or an object containing above propsnumber | object-×
smscreen ≥ 576px, could be a span value or an object containing above propsnumber | object-×
mdscreen ≥ 768px, could be a span value or an object containing above propsnumber | object-×
lgscreen ≥ 992px, could be a span value or an object containing above propsnumber | object-×
xlscreen ≥ 1200px, could be a span value or an object containing above propsnumber | object-×
xxlscreen ≥ 1600px, could be a span value or an object containing above propsnumber | object-×
xxxlscreen ≥ 1920px, could be a span value or an object containing above propsnumber | object-6.3.0×

You can modify breakpoint values by customizing screen[XS|SM|MD|LG|XL|XXL|XXXL] with theme customization (since 5.1.0, sandbox demo).

The breakpoints of responsive grid follow BootStrap 4 media queries rules (not including occasionally part).

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

Native ComponentToken declares no directly extractable own fields. Shared tokens and inheritance are defined by the declarations below.

Declaration source: vendor/components/grid/style/index.ts

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import type { AliasToken, FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

import { genCssVar } from '../../theme/util/genStyleUtils';

// biome-ignore lint/suspicious/noEmptyInterface: ComponentToken need to be empty by default
export interface ComponentToken {}

interface GridRowToken extends FullToken<'Grid'> {
  //
}

interface GridColToken extends FullToken<'Grid'> {
  /**
   * @desc 网格列数
   * @descEN Number of grid columns
   */
  gridColumns: number;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/grid/RowContext.ts
  • vendor/components/grid/col.tsx
  • vendor/components/grid/hooks/useGutter.ts
  • vendor/components/grid/row.tsx
  • vendor/components/grid/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.