Skip to content

Layouts

Spacer

Bit.BlazorUI

BitSpacer generates space between components inside a flex container. Left alone it is flexible and pushes its neighbours apart; given Width, Height, Gap or Size it becomes a fixed space. It renders one empty element, hidden from assistive technologies.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

With no parameters the spacer is flexible: it takes the room the other children do not need, so one spacer pushes its neighbours to the two ends and several split the room evenly. It is a real flex child, so a container gap is added on both sides of it.
Title

Start
End

Fixed size

Width is a fixed gap in pixels, Gap the same in any CSS length (1rem, 5%, var(--my-gap)). A fixed spacer does not grow, and its logical margin never shrinks in a cramped container.

1rem
4ch
10%
end

Vertical

Height is the pixel gap of a column layout, and Vertical moves Gap, Size and MinGap to the block axis. A flexible spacer needs neither: it always grows along the main axis, pinning the last item to the bottom.
Height 8
Height 32
Vertical Gap 3rem
Flexible
Bottom

Grow

Grow is the flex-grow factor (default 1). Several spacers split the leftover room in proportion to it: 1 and 2 give a one third / two thirds split.
A
B
C

A
B
C

Minimum size

MinGap is the floor of a flexible spacer, so its neighbours never touch. Drag the corner of each box to squeeze it: the first spacer keeps its 2rem, the second collapses. A fixed spacer ignores it.
MinGap
2rem

No
MinGap

Element

Element swaps the rendered div for another tag, such as an li in a list-based toolbar or menu, which only accepts list items.
  • Home
  • Products
  • Sign in

Accessibility

A spacer is aria-hidden by default, so screen readers skip the empty box. Give it an AriaLabel when the gap marks a boundary worth announcing: it then renders as a named separator, announced as vertical, since it divides the items of a row, or as horizontal when it is Vertical or only given a Height. A flexible spacer dividing a column adds aria-orientation="horizontal" itself. An explicit role, aria-hidden or aria-orientation attribute still wins.

Cascading parameters

BitParams hands a BitSpacerParams to every spacer under it, so a toolbar or a page sets its rhythm once. The values are defaults, not overrides: a spacer that sets a parameter itself keeps its own.
Cascaded
1.5rem
Own Gap
4rem

Outside
Flexible again

Size

Size takes the fixed space from the theme's spacing scale, so it follows the theme's spacing unit and density. It follows Vertical; Gap, Width and Height win over it. Each step is a public CSS variable: the last row re-sizes Large with --bit-Spacer-large-size.
Small
Medium
Large
End

Vertical Small
Vertical Large
End

Large, re-sized
End

Style & Class

Style and Class land on the spacer element. The space is a margin, so the element has no main-axis size until given one, and it stretches along the cross axis so a decoration shows up in a centered row. Inline styles win over the generated ones.
Style
Class
End

RTL

The fixed space is a logical inline-start margin, so it mirrors with the text direction. Dir on a single spacer moves its space to its other side (the tinted spacers below). A flexible spacer behaves the same either way.
شروع
میانه
پایان

Start
Middle

Start
Middle

CSS variables

The public custom properties this component reads off its root, for what no parameter covers.

Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property: set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it, or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone, as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component falls back to the theme token beside it.

BitSpacer CSS variables

Name Default value Description
--bit-Spacer-small-size 1 theme spacing unit The fixed space of a spacer with Size Small.
--bit-Spacer-medium-size 2 theme spacing units The fixed space of a spacer with Size Medium.
--bit-Spacer-large-size 4 theme spacing units The fixed space of a spacer with Size Large.

API

Every parameter, public member, sub-class and enum this component exposes.

BitSpacer parameters

Name Type Default value Description
Element string? null Gets or sets the custom html element used for the root node, "div" by default. This is what lets a spacer sit in a container that only accepts specific children, such as an "li" inside a list-based toolbar or menu, without breaking the markup of that container.
Gap string? null Gets or sets the fixed amount of space the spacer generates, using any CSS length value (for example "1rem", "5%", or "var(--my-gap)"). The space is created along the inline (horizontal) axis, or along the block (vertical) axis when Vertical is set. It takes precedence over Width, Height and Size on the axis it targets, and like them it turns the spacer from a flexible one into a fixed one, so Grow and MinGap no longer apply.
Grow string? null Gets or sets how much of the leftover space of the container this spacer takes compared to its siblings (the CSS flex-grow factor), 1 by default. Two spacers with the factors "1" and "2" split the leftover space of the container one third to two thirds. It is ignored as soon as the spacer is given a fixed size through Gap, Width, Height or Size.
Height int? null Gets or sets the fixed amount of space the spacer generates along the block (vertical) axis, in pixels. This is the parameter to reach for inside a vertical (column) layout, where the inline-axis Width creates no visible space. Setting it turns the spacer from a flexible one into a fixed one, so Grow and MinGap no longer apply.
MinGap string? null Gets or sets the smallest amount of space a flexible spacer keeps when the container runs out of room, using any CSS length value. It applies to the inline (horizontal) axis, or to the block (vertical) axis when Vertical is set. It only concerns a flexible spacer, so it is ignored as soon as the spacer is given a fixed size through Gap, Width, Height or Size.
Size BitSize? null Gets or sets the fixed amount of space the spacer generates, picked from the spacing scale of the theme, so the resulting length follows the spacing unit and the density of the current theme instead of being hardcoded. It is created along the inline (horizontal) axis, or along the block (vertical) axis when Vertical is set, and like the other fixed sizes it turns the spacer from a flexible one into a fixed one, so Grow and MinGap no longer apply. Gap, Width and Height are more specific, so they take precedence over it.
Vertical bool false Gets or sets a value indicating whether Gap, Size and MinGap apply to the block (vertical) axis instead of the inline (horizontal) one. A flexible spacer does not need this parameter: it always grows along the main axis of its container, whichever that is.
Width int? null Gets or sets the fixed amount of space the spacer generates along the inline (horizontal) axis, in pixels. The space follows the text direction of the spacer, so in a right-to-left context it is created on the right side. Setting it turns the spacer from a flexible one into a fixed one, so Grow and MinGap no longer apply.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
Disabled bool false Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name.
Id string? null Gets or sets the unique identifier for the component's root element.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitSize enum

Name Value Description
Small 0 The small size.
Medium 1 The medium size.
Large 2 The large size.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.