Layouts
Spacer
The purpose of the BitSpacer is to generate space between other components inside a flex container. Left on its own it is flexible: it swallows the leftover room of the container and pushes its neighbours apart, and Grow shares that room out between several spacers in proportion, while MinGap puts a floor under it so its neighbours never touch. Given Width, Height, Gap or Size it becomes a fixed space instead, in pixels, in any CSS length or on the spacing scale of the theme, on the horizontal or the vertical axis. The element it renders is empty and hidden from assistive technologies.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
gap (a BitStack, for instance) that gap is added on both
sides of it.
Title
Fixed size
1rem, 5%,
var(--my-gap)). A fixed spacer no longer grows. The space is created with a logical margin rather
than a width, so it never shrinks when the container gets cramped and it follows the text direction of the page.
Vertical
Grow
Minimum size
2rem, the one without it disappears. It follows the axis of Vertical
like Gap does, and since only a flexible spacer can collapse in the first place, a spacer that was given
a fixed size ignores it.
Element
div, which is not a valid child everywhere: a toolbar or a menu built as a
list only accepts li elements. Element swaps the tag of the rendered root for any other
one, so the spacer can join such a container without breaking its markup, while everything else about it
(the space it generates, the classes and the styles) stays exactly the same.
- Home
- Products
- Sign in
Size
Style & Class
min-width or a border, as the examples below do, to make it visible while laying a page out. It
stretches along the cross axis of its container on its own, so such a decoration shows up even in a container
that centers its items. Inline styles are appended after the ones the component generates, so they win over
them. That element is also marked aria-hidden, so screen readers skip the empty box entirely
unless an AriaLabel is given, which takes the marking back.
RTL
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. |
| 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. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| 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.