Container
Layout container with flexible options and responsive support
Usage
Container
Loading demo...
Simplest container usage:
<template>
<TxContainer>
<p>Content inside the container</p>
</TxContainer>
</template>
Best Practices
- Prefer one
TxContainerper page section. Repeated nested containers make width and padding hard to reason about. - Use responsive
xs/sm/md/lg/xlspans for layout changes instead of hiding duplicate markup per breakpoint. - Keep
guttervalues aligned with the page spacing scale; avoid mixing large gutters with tiny column padding inside the same row. - Use semantic elements inside the layout primitives (
main,aside,nav,section) because the primitives render neutraldivwrappers. - Set
wrap=falseonly for horizontally scrolling or fixed-width toolbars; normal content grids should wrap.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| fluid | boolean | false | Removes the max-width cap and lets the container fill its parent. |
| maxWidth | string | '1200px' | Max width used when fluid is disabled. |
| responsive | boolean | false | Enables the built-in responsive container width classes. |
| padding | 'small' | 'medium' | 'large' | number | 'medium' | Horizontal padding preset or pixel value. |
| margin | 'auto' | string | number | 'auto' | Horizontal margin; auto centers the container. |
Row Props
| Prop | Type | Default | Description |
|---|---|---|---|
| gutter | number | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>> | 0 | Column gutter in pixels, optionally selected by breakpoint. |
| align | 'top' | 'middle' | 'bottom' | 'stretch' | 'stretch' | Vertical alignment for row children. |
| justify | 'start' | 'end' | 'center' | 'space-around' | 'space-between' | 'space-evenly' | 'start' | Horizontal distribution for row children. |
| wrap | boolean | true | Allows columns to wrap onto multiple lines. |
Col Props
| Prop | Type | Default | Description |
|---|---|---|---|
| span | number | 24 | Number of columns occupied in the 24-column grid. |
| offset | number | 0 | Left offset in the 24-column grid. |
| xs | number | - | Span used below 640px. |
| sm | number | - | Span used from 640px to 767px. |
| md | number | - | Span used from 768px to 1023px. |
| lg | number | - | Span used from 1024px to 1279px. |
| xl | number | - | Span used at 1280px and above. |
Slots
| Component | Slot | Props | Description |
|---|---|---|---|
TxContainer | default | - | Page or panel content constrained by the container. |
TxRow | default | - | TxCol children or other flex items. |
TxCol | default | - | Column content. |
Events
TxContainer, TxRow, and TxCol do not emit events.
Container Types
Fluid Containers
Fill the full parent width:
<template>
<TxContainer fluid>
<p>Fluid container, width 100%</p>
</TxContainer>
</template>
Fixed-width Containers
Set max width by breakpoints:
<template>
<TxContainer max-width="1200px">
<p>Container with max width 1200px</p>
</TxContainer>
</template>
Responsive Containers
Different max widths across breakpoints:
<template>
<TxContainer responsive>
<p>Responsive container</p>
</TxContainer>
</template>
Container Spacing
Padding
<template>
<div class="padding-demo">
<TxContainer padding="small">Small padding container</TxContainer>
<TxContainer padding="medium">Medium padding container</TxContainer>
<TxContainer padding="large">Large padding container</TxContainer>
<TxContainer :padding="32">Custom padding container</TxContainer>
</div>
</template>
Margin
<template>
<TxContainer margin="auto">
<p>Centered container</p>
</TxContainer>
</template>
Grid System
Basic Grid
<template>
<TxContainer>
<TxRow>
<TxCol :span="12">
<div class="col-content">Left content</div>
</TxCol>
<TxCol :span="12">
<div class="col-content">Right content</div>
</TxCol>
</TxRow>
</TxContainer>
</template>
<style scoped>
.col-content {
background: var(--tx-bg-color-overlay, #fff);
padding: 16px;
text-align: center;
border-radius: 8px;
}
</style>
Responsive Grid
<template>
<TxContainer>
<TxRow :gutter="{ xs: 8, sm: 16, md: 24, lg: 32 }">
<TxCol :xs="24" :sm="12" :md="8" :lg="6">
<div class="col-content">ResponsiveColumn 1</div>
</TxCol>
<TxCol :xs="24" :sm="12" :md="8" :lg="6">
<div class="col-content">ResponsiveColumn 2</div>
</TxCol>
<TxCol :xs="24" :sm="12" :md="8" :lg="6">
<div class="col-content">ResponsiveColumn 3</div>
</TxCol>
<TxCol :xs="24" :sm="12" :md="8" :lg="6">
<div class="col-content">Responsive column 4</div>
</TxCol>
</TxRow>
</TxContainer>
</template>
Responsive Breakpoints
TouchX UI uses the following breakpoints:
/* Extra small screens */
@media (max-width: 639px) { /* xs */ }
/* Small screens */
@media (min-width: 640px) { /* sm */ }
/* Medium screens */
@media (min-width: 768px) { /* md */ }
/* Large screens */
@media (min-width: 1024px) { /* lg */ }
/* XL screens */
@media (min-width: 1280px) { /* xl */ }
Overview
TxContaineralways renders a block-level wrapper withwidth: 100%;fluidremoves the max-width cap.paddingpresets map to 12 / 16 / 24 px and numeric padding is clamped at zero.margin="auto"centers the container; string or numeric margins are applied horizontally as0 <value>.TxRowcomputes one gutter per active breakpoint and exposes it as--tx-row-gutter; columns split that gutter into left/right padding.- The row cancels that padding at both outer edges with negative margins, and its width is
calc(100% + var(--tx-row-gutter))to pay for them. A plain100%resolves against the containing block's content width, so the negative margins shifted the row left without widening it and it finished a full gutter short on the right — inside a paddedTxContainerthat showed up as 16px of inset on the left against 24px on the right at an 8px gutter. TxColclampsspanandoffsetto the 0–24 grid, falling back tospanwhen a breakpoint-specific prop is not provided.
Technologies
- Reviewed against
packages/tuffex/packages/components/src/container/src/TxContainer.vue,TxRow.vue,TxCol.vue, andcontainer.test.ts. - Existing tests cover container CSS variables, padding clamp, fluid/responsive classes, custom margin, row gutter/alignment/justification/wrap styles, responsive gutter selection, and column span/offset/responsive styles.
- Accessibility note: all three primitives render neutral
divelements; add semantic landmarks and headings in the slotted content instead of expecting the layout primitive to supply document structure. - Component source:
packages/tuffex/packages/components/src/container/src/TxContainer.vue,TxRow.vue, andTxCol.vue. - Verified coverage:
packages/tuffex/packages/components/src/container/__tests__/container.test.tsverifies spacing variables, clamping, responsive classes, row flex styles, responsive gutter, and column sizing.查看源码packages/tuffex/packages/components/src/container/index.ts
Customization
CSS Variables
.custom-container {
--tx-container-max-width: 1200px;
--tx-container-padding: 16px;
--tx-row-gutter: 16px;
}