GridСетка
Раскладка на 24 колонки. Row раскладывает дочерние Col; колонка занимает span из 24 и переносится на следующую строку целиком, если не помещается. Строки выравнивают и распределяют колонки, а сами колонки можно сдвигать, переупорядочивать, скрывать и менять по ширине экрана. Адаптивные значения вычисляет CSS, поэтому сервер и браузер рисуют одну и ту же страницу. Breakpoints сообщает коду, каким брейкпоинтам соответствует экран.
Когда использовать
- Используйте сетку, чтобы разложить страницу или раздел по равным колонкам, выровненным от строки к строке.
- Используйте адаптивные свойства (
xs…xxxl), когда раскладка должна меняться с шириной экрана. - Для одномерных отступов без числа колонок проще обычный flex или CSS grid в собственных стилях.
Примеры
col-24
col-12
col-12
col-8
col-8
col-8
col-6
col-6
col-6
col-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- Columns go into a Row. A column takes span of the 24; the Row is as wide as its parent. -->
<div class="stack">
<Row>
<Col span={24}><div class="box">col-24</div></Col>
</Row>
<Row>
<Col span={12}><div class="box">col-12</div></Col>
<Col span={12}><div class="box alt">col-12</div></Col>
</Row>
<Row>
<Col span={8}><div class="box">col-8</div></Col>
<Col span={8}><div class="box alt">col-8</div></Col>
<Col span={8}><div class="box">col-8</div></Col>
</Row>
<Row>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box alt">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box alt">col-6</div></Col>
</Row>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
gutter={16}
col-6
col-6
col-6
col-6
gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }} (resize the window)
col-6
col-6
col-6
col-6
gutter={[16, 24]}: horizontal and vertical
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
gutter="2rem": a CSS length
col-6
col-6
col-6
col-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">{'gutter={16}'}</span>
<!-- A number is pixels. The Row does not grow past its parent: there is no negative margin. -->
<Row gutter={16}>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}'} (resize the window)</span>
<!-- One value per breakpoint; a breakpoint that is not given keeps the value of the next smaller one. -->
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'gutter={[16, 24]}'}: horizontal and vertical</span>
<Row gutter={[16, 24]}>
{#each [0, 1, 2, 3, 4, 5, 6, 7] as index (index)}
<Col span={6}><div class="box">col-6</div></Col>
{/each}
</Row>
</div>
<div class="field">
<span class="caption">gutter="2rem": a CSS length</span>
<Row gutter="2rem">
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
</style>
col-8
col-8 offset-8
col-6 offset-6
col-6 offset-6
col-12 offset-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- offset skips that many columns before the column. -->
<div class="stack">
<Row>
<Col span={8}><div class="box">col-8</div></Col>
<Col span={8} offset={8}><div class="box alt">col-8 offset-8</div></Col>
</Row>
<Row>
<Col span={6} offset={6}><div class="box">col-6 offset-6</div></Col>
<Col span={6} offset={6}><div class="box alt">col-6 offset-6</div></Col>
</Row>
<Row>
<Col span={12} offset={6}><div class="box">col-12 offset-6</div></Col>
</Row>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
push={6} and pull={18}: the first column in the DOM is drawn second
col-18 push-6
col-6 pull-18
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- push and pull move a column visually. The DOM order, the Tab order and the reading order do not change. -->
<div class="stack">
<div class="field">
<span class="caption">{'push={6} and pull={18}'}: the first column in the DOM is drawn second</span>
<Row>
<Col span={18} push={6}><div class="box">col-18 push-6</div></Col>
<Col span={6} pull={18}><div class="box alt">col-6 pull-18</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
justify="start"
col-4
col-4
col-4
col-4
justify="center"
col-4
col-4
col-4
col-4
justify="end"
col-4
col-4
col-4
col-4
justify="space-between"
col-4
col-4
col-4
col-4
justify="space-around"
col-4
col-4
col-4
col-4
justify="space-evenly"
col-4
col-4
col-4
col-4
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
const values = ['start', 'center', 'end', 'space-between', 'space-around', 'space-evenly'] as const;
</script>
<div class="stack">
{#each values as value (value)}
<div class="field">
<span class="caption">justify="{value}"</span>
<div class="area">
<Row justify={value}>
{#each [0, 1, 2, 3] as index (index)}
<Col span={4}><div class="box" class:alt={index % 2 === 1}>col-4</div></Col>
{/each}
</Row>
</div>
</div>
{/each}
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.area {
background: var(--ads-color-bg-container-disabled);
border-radius: 4px;
}
</style>
align="top"
col-4
col-4
col-4
col-4
align="middle"
col-4
col-4
col-4
col-4
align="bottom"
col-4
col-4
col-4
col-4
align="stretch"
col-4
col-4
col-4
col-4
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
const values = ['top', 'middle', 'bottom', 'stretch'] as const;
const heights = [100, 50, 120, 80];
</script>
<div class="stack">
{#each values as value (value)}
<div class="field">
<span class="caption">align="{value}"</span>
<div class="area">
<Row justify="space-around" align={value}>
{#each heights as height, index (index)}
<Col span={4}>
<!-- stretch makes every column as tall as the line. The box of a column fills it when it is as tall as its parent. -->
<div
class="box"
class:alt={index % 2 === 1}
class:fill={value === 'stretch' && index !== 0}
style:height={value !== 'stretch' ? `${height}px` : index === 0 ? `${height}px` : undefined}
>
col-4
</div>
</Col>
{/each}
</Row>
</div>
</div>
{/each}
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.area {
background: var(--ads-color-bg-container-disabled);
border-radius: 4px;
}
.fill {
height: 100%;
box-sizing: border-box;
}
</style>
Written 1, 2, 3, 4; drawn 1, 2, 3, 4
1 order-1
2 order-2
3 order-3
4 order-4
Written 1, 2, 3, 4; drawn 4, 3, 2, 1
1 order-4
2 order-3
3 order-2
4 order-1
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- order changes how the columns are drawn, not their place in the DOM (a screen reader and Tab keep the written order). -->
<div class="stack">
<div class="field">
<span class="caption">Written 1, 2, 3, 4; drawn 1, 2, 3, 4</span>
<Row>
<Col span={6} order={1}><div class="box">1 order-1</div></Col>
<Col span={6} order={2}><div class="box alt">2 order-2</div></Col>
<Col span={6} order={3}><div class="box">3 order-3</div></Col>
<Col span={6} order={4}><div class="box alt">4 order-4</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">Written 1, 2, 3, 4; drawn 4, 3, 2, 1</span>
<Row>
<Col span={6} order={4}><div class="box">1 order-4</div></Col>
<Col span={6} order={3}><div class="box alt">2 order-3</div></Col>
<Col span={6} order={2}><div class="box">3 order-2</div></Col>
<Col span={6} order={1}><div class="box alt">4 order-1</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
flex={2} and flex={3}: a number n is "n n auto"
2 / 5
3 / 5
flex="100px" and flex="auto": a fixed width and the rest
100px
Fill rest
flex="1 1 200px" and flex="0 1 300px": a raw flex value
1 1 200px
0 1 300px
flex="none" and flex="auto"
none
auto with no-wrap
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">{'flex={2} and flex={3}'}: a number n is "n n auto"</span>
<Row>
<Col flex={2}><div class="box">2 / 5</div></Col>
<Col flex={3}><div class="box alt">3 / 5</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="100px" and flex="auto": a fixed width and the rest</span>
<Row>
<Col flex="100px"><div class="box">100px</div></Col>
<Col flex="auto"><div class="box alt">Fill rest</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="1 1 200px" and flex="0 1 300px": a raw flex value</span>
<Row>
<Col flex="1 1 200px"><div class="box">1 1 200px</div></Col>
<Col flex="0 1 300px"><div class="box alt">0 1 300px</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="none" and flex="auto"</span>
<Row wrap={false}>
<Col flex="none"><div class="box">none</div></Col>
<Col flex="auto"><div class="box alt">auto with no-wrap</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
wrap
wrap={true}
Three columns of 12: the third does not fit in a line
col-12
col-12
col-12
<script lang="ts">
import { Col, Row, Switch } from 'svelte-ant-design';
let wrap = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">wrap</span>
<div class="row">
<Switch bind:checked={wrap} aria-label="wrap" />
<span role="status">{`wrap={${wrap}}`}</span>
</div>
</div>
<div class="field">
<span class="caption">Three columns of 12: the third does not fit in a line</span>
<!-- With wrap, a column that does not fit moves to the next line as a whole. Without it the columns keep their width and run past the end of the Row. -->
<div class="strip">
<Row {wrap}>
<Col span={12}><div class="box">col-12</div></Col>
<Col span={12}><div class="box alt">col-12</div></Col>
<Col span={12}><div class="box">col-12</div></Col>
</Row>
</div>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.strip {
overflow-x: auto;
}
</style>
Outer gutter 16; the inner Row on the left has gutter 4, the one on the right none
12 / 24 of 12
12 / 24 of 12
8
16
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- A Row inside a Col fills the content box of the column and has a gutter of its own. -->
<div class="stack">
<div class="field">
<span class="caption">Outer gutter 16; the inner Row on the left has gutter 4, the one on the right none</span>
<Row gutter={16}>
<Col span={12}>
<Row gutter={4}>
<Col span={12}><div class="box">12 / 24 of 12</div></Col>
<Col span={12}><div class="box alt">12 / 24 of 12</div></Col>
</Row>
</Col>
<Col span={12}>
<Row>
<Col span={8}><div class="box">8</div></Col>
<Col span={16}><div class="box alt">16</div></Col>
</Row>
</Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
xs 2/20/2, sm 4/16/4, md 6/12/6, lg 8/8/8, xl 10/4/10, xxl 11/2/11, xxxl 12/0/12
Col
Col
Col
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- xs is the base for every width; each larger breakpoint applies from its minimum width up. Resize the window. -->
<div class="stack">
<div class="field">
<span class="caption">xs 2/20/2, sm 4/16/4, md 6/12/6, lg 8/8/8, xl 10/4/10, xxl 11/2/11, xxxl 12/0/12</span>
<Row>
<Col xs={2} sm={4} md={6} lg={8} xl={10} xxl={11} xxxl={12}><div class="box">Col</div></Col>
<Col xs={20} sm={16} md={12} lg={8} xl={4} xxl={2} xxxl={0}><div class="box alt">Col</div></Col>
<Col xs={2} sm={4} md={6} lg={8} xl={10} xxl={11} xxxl={12}><div class="box">Col</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
flex 100% / 50% / 40% / 20% / 10% from xs / sm / md / lg / xl
Col
Col
Col
Col
Col
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- A breakpoint object can carry flex: a share of the line that changes with the screen. Resize the window. -->
<div class="stack">
<div class="field">
<span class="caption">flex 100% / 50% / 40% / 20% / 10% from xs / sm / md / lg / xl</span>
<Row>
{#each [0, 1, 2, 3, 4] as index (index)}
<Col xs={{ flex: '100%' }} sm={{ flex: '50%' }} md={{ flex: '40%' }} lg={{ flex: '20%' }} xl={{ flex: '10%' }}>
<div class="box" class:alt={index % 2 === 1}>Col</div>
</Col>
{/each}
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
xs span 5 offset 1; lg span 6 offset 2 (resize the window)
Col
Col
Col
xs={12}, md order 2 / 1: drawn in the other order from md
First in the DOM
Second in the DOM
md push 6 and pull 18: swapped visually from md, the DOM order stays
First in the DOM
Second in the DOM
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- span, offset, push, pull, order and flex go inside a breakpoint object; xs={6} is the same as xs={{ span: 6 }}.
Each key cascades on its own: the offset of xs still applies where lg gives only a span. -->
<div class="stack">
<div class="field">
<span class="caption">xs span 5 offset 1; lg span 6 offset 2 (resize the window)</span>
<Row>
<Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box">Col</div></Col>
<Col xs={{ span: 11, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box alt">Col</div></Col>
<Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box">Col</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'xs={12}'}, md order 2 / 1: drawn in the other order from md</span>
<Row>
<Col xs={12} md={{ span: 12, order: 2 }}><div class="box">First in the DOM</div></Col>
<Col xs={12} md={{ span: 12, order: 1 }}><div class="box alt">Second in the DOM</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">md push 6 and pull 18: swapped visually from md, the DOM order stays</span>
<Row>
<Col xs={12} md={{ span: 18, push: 6 }}><div class="box">First in the DOM</div></Col>
<Col xs={12} md={{ span: 6, pull: 18 }}><div class="box alt">Second in the DOM</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
Horizontal gutter (px)
Vertical gutter (px)
Columns in a row
<Row gutter={[16, 16]}> with 4 columns of span 6, twice
Column
Column
Column
Column
Column
Column
Column
Column
<script lang="ts">
import { Col, RadioGroup, Row } from 'svelte-ant-design';
const gutters = [8, 16, 24, 32, 40, 48];
let horizontal = $state(16);
let vertical = $state(16);
let count = $state(4);
const counts = [2, 3, 4, 6, 8, 12];
</script>
<div class="stack">
<div class="field">
<span class="caption">Horizontal gutter (px)</span>
<RadioGroup bind:value={horizontal} optionType="button" options={gutters} aria-label="Horizontal gutter" />
</div>
<div class="field">
<span class="caption">Vertical gutter (px)</span>
<RadioGroup bind:value={vertical} optionType="button" options={gutters} aria-label="Vertical gutter" />
</div>
<div class="field">
<span class="caption">Columns in a row</span>
<RadioGroup bind:value={count} optionType="button" options={counts} aria-label="Columns in a row" />
</div>
<div class="field">
<span class="caption">{`<Row gutter={[${horizontal}, ${vertical}]}> with ${count} columns of span ${24 / count}, twice`}</span>
<Row gutter={[horizontal, vertical]}>
{#each Array.from({ length: count * 2 }, (_, index) => index) as index (index)}
<Col span={24 / count}><div class="box" class:alt={index >= count}>Column</div></Col>
{/each}
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
screens.current
screens.xs ... screens.xxxl (xs is true below 576 px, the others from their width up)
xs: true
sm: false
md: false
lg: false
xl: false
xxl: false
xxxl: false
{#if screens.md}: markup that depends on the screen
The screen is narrower than 768 px
<script lang="ts">
import { Breakpoints, Col, Row } from 'svelte-ant-design';
// The values are read from the screen when the object is created, so they are right on the first render.
// On a server, where there is no screen, they follow options.fallback (default 'xs').
const screens = new Breakpoints();
const names = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'] as const;
</script>
<div class="stack">
<div class="field">
<span class="caption">screens.current</span>
<output>{screens.current}</output>
</div>
<div class="field">
<span class="caption">screens.xs ... screens.xxxl (xs is true below 576 px, the others from their width up)</span>
<Row gutter={[8, 8]}>
{#each names as name (name)}
<Col xs={12} sm={8} md={6}>
<div class="box" class:alt={!screens[name]}>{name}: {screens[name]}</div>
</Col>
{/each}
</Row>
</div>
<div class="field">
<span class="caption">{'{#if screens.md}'}: markup that depends on the screen</span>
{#if screens.md}
<div class="box">The screen is at least 768 px wide</div>
{:else}
<div class="box alt">The screen is narrower than 768 px</div>
{/if}
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
Row API
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| align | Вертикальное выравнивание колонок строки: top, middle, bottom или stretch. Объект задаёт значение для каждого брейкпоинта. | RowAlign | Partial<Record<Breakpoint, RowAlign>> | 'top' |
| justify | Горизонтальное расположение колонок строки: start, end, center, space-around, space-between или space-evenly. Объект задаёт значение для каждого брейкпоинта. | RowJustify | Partial<Record<Breakpoint, RowJustify>> | 'start' |
| gutter | Отступ между колонками. Число — пиксели, строка — CSS-длина (2rem, 5vw, calc()), объект задаёт значение для каждого брейкпоинта, а пара — это [горизонтальный, вертикальный] (каждый может быть любым из первых трёх). Строка, не являющаяся длиной, игнорируется. Отрицательное или нечисловое значение в разработке бросает ошибку. | Gutter | [Gutter, Gutter] | 0 |
| wrap | Переносятся ли колонки, которые не помещаются, на следующую строку. С false они остаются в одной строке, сохраняют ширину и выходят за конец Row. | boolean | true |
| children | Колонки (Col). Прочие дочерние элементы раскладываются как обычные flex-элементы. | Snippet | — |
| class | Дополнительный класс Row. | string | — |
| style | Инлайн-стиль корня. Он записывается после значений компонента, поэтому побеждает на том же свойстве. | string | — |
| native attributes | Всё остальное попадает на корневой <div>: id, role, aria-*, data-*, обработчики событий. | HTMLAttributes<HTMLDivElement> | — |
Отличия от Ant Design:
gutter — это flex-gap, а не отрицательные поля с padding у колонок, поэтому Row не выходит за родителя (у Row в Ant Design выходит, и страница получает горизонтальный скролл), а фон самой колонки не закрашивает gutter; адаптивные значения — только CSS, а брейкпоинты фиксированы (576, 768, 992, 1200, 1600 и 1920 px), тема их не меняет; Breakpoints заменяет хук Grid.useBreakpoint и верен уже на первом рендере; classNames/styles нет: ни в одной из трёх библиотек Ant Design у сетки их нет.API колонки Col
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| span | Сколько из 24 колонок занять. 0 — это display: none. Без него колонка сохраняет ширину содержимого. Отрицательное или нечисловое значение в разработке бросает ошибку. | number | — |
| offset | Пустые колонки перед этой. | number | 0 |
| push | Сдвигает колонку на столько колонок к концу строки, только визуально. Порядок в DOM не меняется. | number | 0 |
| pull | Сдвигает колонку на столько колонок к началу строки, только визуально. Если заданы push и pull, колонка сдвигается на разность. | number | 0 |
| order | Flex-order: как рисуется колонка, а не её место в DOM. Целое число, допустимы отрицательные. | number | 0 |
| flex | Число n — это flex: n n auto (0 тоже значение); строка из цифр — n 1 0px; одна длина или процент (100px, 30%) — фиксированная ширина, 0 0 <длина>; любая другая строка используется как есть. Побеждает ширину от span. | string | number | — |
| xs | От 0 px и выше: основа для любой ширины. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| sm | От 576 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| md | От 768 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| lg | От 992 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| xl | От 1200 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| xxl | От 1600 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| xxxl | От 1920 px и выше. Число — это span; объект принимает свойства ColSize. | number | ColSize | — |
| children | Содержимое колонки. | Snippet | — |
| class | Дополнительный класс колонки. | string | — |
| style | Инлайн-стиль корня. Он записывается после значений компонента, поэтому побеждает на том же свойстве. | string | — |
| native attributes | Всё остальное попадает на корневой <div>: id, role, aria-*, data-*, обработчики событий. | HTMLAttributes<HTMLDivElement> | — |
ColSize: ключи объекта брейкпоинта
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| span | Сколько из 24 колонок занять; 0 скрывает колонку на этом брейкпоинте. | number | — |
| offset | Пустые колонки перед этой. | number | — |
| push | Визуальный сдвиг к концу строки, в колонках. | number | — |
| pull | Визуальный сдвиг к началу строки, в колонках. | number | — |
| order | Flex-order. | number | — |
| flex | Сырое значение flex, как у свойства flex. | string | number | — |
Breakpoints: брейкпоинты в коде
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| new Breakpoints(options?) | Создаёт читателя. Значения берутся с экрана сразу, поэтому в браузере верны уже на первом рендере. Слушатели существуют, только пока значения читает что-то реактивное. | (options?: BreakpointsOptions) => Breakpoints | — |
| options.fallback | Брейкпоинт, который сообщается там, где экрана нет (на сервере): флаги такие, как у экрана ровно той ширины, с которой начинается этот брейкпоинт. Неизвестное значение в разработке бросает ошибку. | Breakpoint | 'xs' |
| xs | Истинно, пока ширина меньше 576 px. | boolean | — |
| sm | Истинно от 576 px и выше. | boolean | — |
| md | Истинно от 768 px и выше. | boolean | — |
| lg | Истинно от 992 px и выше. | boolean | — |
| xl | Истинно от 1200 px и выше. | boolean | — |
| xxl | Истинно от 1600 px и выше. | boolean | — |
| xxxl | Истинно от 1920 px и выше. | boolean | — |
| current | Наибольший подходящий брейкпоинт (xs при ширине меньше 576 px). | Breakpoint | — |
BREAKPOINTS: минимальные ширины в пикселях
| Свойство | По умолчанию |
|---|---|
| xs | 0 |
| sm | 576 |
| md | 768 |
| lg | 992 |
| xl | 1200 |
| xxl | 1600 |
| xxxl | 1920 |
Доступность
- Row и Col — обычные
<div>без собственной роли, имени и состояния. Это раскладка, а не таблица данных, поэтому ролейrow,cellилиgridу них нет. Если разметке нужна роль (список, область), передайтеroleилиaria-*как нативные атрибуты. - Порядок чтения — это порядок в DOM.
order,pushиpullменяют только отрисовку колонок, поэтому порядок Tab и скринридера может отличаться от того, что видит глаз (WCAG 2.4.3 и 1.3.2). Пишите колонки в том порядке, в каком их читать, а эти свойства используйте для оформления. spanравный0— этоdisplay: none: содержимое скрыто и от вспомогательных технологий, а его элементы управления выпадают из порядка Tab.- Сетка не рисует цвета, границ и анимации, и в ней нет интерактивных элементов, поэтому проверки контраста, forced-colors, reduced-motion, IME, касаний и скринридера к ней не применимы. Порядок чтения и отсутствие ролей покрыты тестами.