Layouts
Container
The BitContainer component centers the content of a page in a column with a maximum width and side gutters: the block every site otherwise copies into its pages (a max-width, margin-inline: auto and a padding per breakpoint). It takes the whole width it is given up to MaxWidth (80rem by default, gutters included), centers itself in what is left, and pads its content with a gutter that grows from a phone to a desktop unless NoGutter removes it.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
spacing(2) on a phone,
spacing(3) from the sm breakpoint (600px) and spacing(4) from md
(960px): resize the window to watch it step.
MaxWidth
none
lets the container span the whole width it is given and keep only its gutters.
NoGutter
Full-width bands
Element
div for another tag: a main for the main content
of the page, a section or an article for a region of it. Only the semantics change,
so a landmark is worth naming: AriaLabel puts an aria-label on the root, which assistive
technologies read out as the name of the region.
Cascading parameters
Style & Class
--bit-Container-max-width, --bit-Container-padding-inline (a gutter set
there holds at every width) and --bit-Container-padding-block. A MaxWidth or a
NoGutter written on a container still wins over them.
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.
BitContainer CSS variables
| Name | Default value | Description |
|---|---|---|
| --bit-Container-max-width | 80rem | Maximum width of the container, gutters included. The MaxWidth parameter wins over it. It inherits, so a value set on a container also reaches the containers nested in it; MaxWidth is the way to size one container alone. |
| --bit-Container-padding-inline | spacing(2), spacing(3) from sm, spacing(4) from md | The gutters on the two sides of the content. A value set here holds at every width (the steps are the default's alone), and NoGutter wins over it. |
| --bit-Container-padding-block | 0 | Room above and below the content. |
API
Every parameter, public member, sub-class and enum this component exposes.
BitContainer parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | The content to be rendered inside the BitContainer. |
| Element | string? | null | Gets or sets the custom html element used for the root node, "div" by default. A container that holds the main content of the page is more meaningful as a main, one that holds a region of it as a section or an article. Only the tag name changes, and with it the semantics reported to assistive technologies, so a landmark element given here is worth pairing with an AriaLabel that names it. |
| MaxWidth | string? | null | Gets or sets the maximum width of the BitContainer, in which its content is then centered. Takes any CSS length (for example 1200px or 75rem), or none for a container that spans the whole width it is given and only keeps its gutters. The width includes the gutters. An explicit value wins over the --bit-Container-max-width variable; left unset, the container is 80rem (1280px, the large breakpoint) wide at most unless that variable says otherwise. |
| NoGutter | bool | false | Removes the inline paddings (the gutters) of the BitContainer, so its content can span its full width. It wins over the --bit-Container-padding-inline variable; the block padding is not a gutter, so it is left alone. |
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. |
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.