Layout
A requested width or height describes the border box. Padding and borders consume space inside it; margins are outside. A 20-cell-wide box with single borders on both sides and one cell of horizontal padding on each side has 16 cells left for content.
Choose a layout
Section titled “Choose a layout”- Block and inline: Blocks stack vertically. An inline formatting context (IFC) shapes text into grapheme clusters and fits inline items into lines. A glyph can occupy more than one cell. Use
TextOverflow(style.TextOverflowEllipsis)for truncated, non-wrapping text; useOverflowWrapwhen an otherwise unbreakable run should wrap. - Flexbox: Use
DisplayFlexfor one main axis. SetFlexDirectionto choose row or column,JustifyContentalong that axis andAlignItemsacross it. EnableFlexWrapif items should start new lines instead of fitting one line. - Grid: Use
DisplayGridwhen multiple rows need the same column boundaries. A fixed track takes cells first;frtracks divide the remaining space proportionally. Unplaced children are auto-placed. Place a child explicitly withGridColumn(style.GridLine(2))or span tracks withstyle.Span(2).
Size a toolbar along one axis
Section titled “Size a toolbar along one axis”Set direction, alignment, and spacing on the container. Set Flex on the item that should absorb spare width. Here the status and Publish button divide spare space in a 2:1 ratio:
direction := style.FlexRowtrack := style.S(). Display(style.DisplayFlex). Width(style.Cells(34)). Gap(1)
status := element.Text("All changes saved")summary := element.Box(status).Style( style.S(). Flex(2). Background(demo.Default.Colors.AccentSoft),)publish := element.Button("Publish"). Style(demo.Default.PrimaryButton.Flex(1)). OnPress(func() { status.SetData("Published") })
toolbar := element.Box(summary, publish).Style( track.FlexDirection(direction),)toggle := element.Button("Switch axis"). Style(demo.Default.Button). OnPress(func() { if direction == style.FlexRow { direction = style.FlexColumn } else { direction = style.FlexRow } toolbar.Style(track.FlexDirection(direction)) })Flex(1) means grow by one share, allow shrinking, and start from an automatic basis. To control all three, pass grow, shrink, and a dimension, for example Flex(0, 0, style.Cells(12)) for a fixed sidebar.
Align rows to shared grid tracks
Section titled “Align rows to shared grid tracks”Reserve 18 cells for names, then divide the remaining track space 2:1 between details and status. GridLine takes a one-based start line; Span specifies a count, not a start line.
columns := style.S(). Display(style.DisplayGrid). GridTemplateColumns(style.Cells(18), style.Fr(2), style.Fr(1)). GridColumnGap(1)
jobs := element.Box( element.Box("Job"), element.Box("Details").Style(style.S().GridColumn(style.GridLine(2))), element.Box("Status"), element.Box("Build"), element.Box("Waiting for a runner").Style( style.S().GridColumn(style.Span(2)), ),).Style(columns)Share space between table cells and list markers
Section titled “Share space between table cells and list markers”Table columns are sized across all rows. A spanning cell occupies slots in neighboring rows or columns; omit those slots rather than adding empty cells. Touching borders implicitly collapse onto one terminal column or row, so two bordered neighbors share one line.
c := demo.Default.Colorscell := func(text string) *element.TableCellElement { return element.TD(text).Style( style.S(). Border(style.SingleBorder().Color(c.Border)). Background(c.CardBg). Foreground(c.Text). Padding(0, 1), )}
runs := element.Table(element.TBody( element.TR(cell("Queue").SetColSpan(2)), element.TR(cell("Release").SetRowSpan(2), cell("Build")), element.TR(cell("Publish")),))Read spans with ColSpan() and RowSpan(). For a list, layout supplies the marker rather than adding a DOM child; change ListStyleType instead of prefixing every item with a bullet:
kinds := []style.ListStyleType{ style.ListStyleDisc, style.ListStyleCircle, style.ListStyleDecimal,}index := 0
checks := func(kind style.ListStyleType) dom.Node { lint, test := element.LI("Lint"), element.LI("Test") if kind == style.ListStyleDecimal { return element.OL(lint, test) } return element.UL(lint, test).Style(style.S().ListStyleType(kind))}
list := element.Box(checks(kinds[index]))truncate := style.S(). Width(style.Cells(17)). WhiteSpace(style.WhiteSpaceNoWrap). TextOverflow(style.TextOverflowEllipsis)
title := element.Box("Continuous integration checks").Style(truncate)toggle := element.Button("Next marker"). Style(demo.Default.Button). OnPress(func() { index = (index + 1) % len(kinds) list.RemoveChild(list.FirstChild()) list.AddChild(checks(kinds[index])) })Clipping and scrolling
Section titled “Clipping and scrolling”For a bounded pane, give it a height and set OverflowY(style.OverflowAuto). Non-visible overflow clips descendants, not the pane’s own border. Scroll() reads the requested offsets, ScrollTo(x, y) sets them, and ScrollBy(dx, dy) moves relative to them. Paint clamps translation to the content extent for scroll/auto containers. ScrollbarX(true) and ScrollbarY(true) enable visual scrollbars; Scrollbar styles their appearance.
This build log reserves four rows including its border. The buttons stay outside the pane, so scrolling never moves them:
c := demo.Default.ColorslogPane := element.Box( element.Box("Queued"), element.Box("Building"), element.Box("Testing"), element.Box("Done"),).Style( style.S(). Height(style.Cells(4)). Border(style.SingleBorder().Color(c.Border)). Background(c.CardBg). Foreground(c.Text). Padding(0, 1). OverflowY(style.OverflowAuto). ScrollbarY(true),)
controls := element.Box( element.Button("Next line"). Style(demo.Default.PrimaryButton). OnPress(func() { logPane.ScrollBy(0, 1) }), element.Button("Back to top"). Style(demo.Default.Button). OnPress(func() { logPane.ScrollTo(0, 0) }),).Style(demo.Default.ButtonRow)CSS-in-Kite property reference
Section titled “CSS-in-Kite property reference”| CSS concern | style.S() builders |
Units or behavior |
|---|---|---|
| Display and sizing | Display, Width, Height, MinWidth, MaxWidth, MinHeight, MaxHeight |
Dimensions such as style.Cells(24) or style.Percent(50) |
| Box edges | Padding, Margin, Border |
Cell insets and border glyphs |
| Flex layout | FlexDirection, FlexWrap, Gap, JustifyContent, AlignItems, AlignContent |
Main and cross axes |
| Flex items | Flex, AlignSelf, Order |
Sizing, alignment override, visual order |
| Grid tracks | GridTemplateColumns, GridTemplateRows, GridColumnGap, GridRowGap |
GridTrackSize aliases Dimension; Repeat builds a track slice |
| Grid placement | GridColumn, GridRow |
GridLine, GridArea, or Span |
| Text layout | TextAlign, WhiteSpace, TextWrap, WordBreak, OverflowWrap, TextOverflow |
Alignment, line breaking, truncation |
| Paint and emphasis | Foreground, Background, Bold, Italic, Underline, Strikethrough, Reverse |
Cell colors and terminal attributes |
| Lists and selection | ListStyleType, SelectionForeground, SelectionBackground |
Marker and selected-text appearance |
| Overflow and cursor | OverflowX, OverflowY, Scrollbar, Cursor |
Per-axis clipping and focused cursor appearance |