Methods for controlling the alignment of content within flex and grid containers.
import { View } from "tile-css"
const Container = View('100%', '100vh')
.align({ x: 'center', y: 'end' }) // align contents to bottom center
.element();
export const AppLayout = () => (
<ResponsiveLayout>
<Header />
<MainContent />
<Footer />
</ResponsiveLayout>
);
Import these functions from "tile" to create pre-configured aligned layouts:
import { Frame, VStack, HStack } from "tile";
Creates a flexible frame layout that centers its content by default.
const CenteredFrame = Frame(200, 200).element();
const CustomAlignedFrame = Frame('100%', 'auto', { x: 'end', y: 'start' }).element();
Creates a vertically stacked layout.
const CenteredVStack = VStack({ align: 'center' }).element();
Creates a horizontally stacked layout.
const EndAlignedHStack = HStack({ align: 'end' }).element();
Sets the layout to be a flexbox and centers the contents automatically.
const CenteredContent = View()
.center()
.element();
Controls the alignment of content within a container.
const CenteredContent = View()
.align('center')
.element();
const ComplexAlignment = View()
.align({ horizontal: 'start', vertical: 'center' })
.element();
You can specify alignment in several ways:
-
Single value for both axes:
View().align('center')
-
Separate values for horizontal and vertical alignment:
View().align(['start', 'center'])
-
Object with
horizontal
andvertical
properties:View().align({ horizontal: 'end', vertical: 'top' })
-
Object with
x
andy
properties (aliases forhorizontal
andvertical
):View().align({ x: 'left', y: 'bottom' })
'top'
,'center'
,'bottom'
'left'
,'right'
'start'
,'end'
'leading'
,'trailing'
-
For flex containers:
- In row direction, horizontal alignment affects
justifyContent
and vertical alignment affectsalignItems
. - In column direction, vertical alignment affects
justifyContent
and horizontal alignment affectsalignItems
.
- In row direction, horizontal alignment affects
-
For grid containers:
- Horizontal alignment affects
justifyContent
. - Vertical alignment affects
alignContent
.
- Horizontal alignment affects
Centering content in a flex container:
const CenteredFlex = View()
.display('flex')
.align('center')
.element();
Aligning content in a grid container:
const AlignedGrid = View()
.display('grid')
.align({ horizontal: 'end', vertical: 'start' })
.element();
Complex alignment in a flex container:
const ComplexFlexAlign = View()
.display('flex')
.flexDirection('column')
.align(['center', 'start'])
.element();