Skip to content

Layouts

Layout

Bit.BlazorUI

The BitLayout component builds the base UI structure of an application: a header, a footer and a middle row that holds a nav panel, the main content and an aside. Every section renders the HTML element that carries its landmark role, so a screen reader can jump straight to any of them, and an optional skip link gives a keyboard user the same shortcut to the content. The layout is only as tall as its content, which lets it be dropped into a box of any size, and each of its sections can be sized, hidden, bordered, pinned while the page scrolls or given a scrollport of its own.

Usage

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

Basic

The three sections of a page in their reading order: Header, Main and Footer. They render as a header, a main and a footer element, which are the banner, main and contentinfo landmarks of the page. The header and the footer are only rendered when they are given content, so a layout with a Main alone is just that one section.

Header
Main

NavPanel

The NavPanel sits next to the main content in the middle row and renders as a nav element, the navigation landmark of the page. NavPanelWidth is the room the main content leaves for it in pixels; the panel itself keeps sizing to its own content, so a panel that collapses to a rail or turns into an overlay drawer on a small screen only has to be given a width of 0 for the main content to span the whole row again. HideNavPanel takes the section out of the markup altogether, which is what a landing page or a full screen editor inside the same layout needs.


Header
Main

Aside

The Aside is the panel on the other side of the main content, rendered as an aside element - the complementary landmark - which is where a table of contents, a filter panel or an inspector belongs. It works exactly like the nav panel: AsideWidth reserves its room in the main content and HideAside gives it back. With both panels present the layout is the classic three column page.


Header
Main

Reverse

The middle row is laid out in the reading direction, so the nav panel starts on the left in an LTR layout and on the right in an RTL one. ReverseNavPanel flips that order: the nav panel moves to the end of the row and the aside to its start, without either of them changing what it means to a screen reader.


Header
Main

FullHeightPanels

By default the header runs across the top of everything and the panels sit under it, which is the shape of a web page. FullHeightPanels gives the shape of an application instead: the nav panel and the aside run down the whole height of the layout and the header, the main content and the footer share the column left between them - a workspace with a permanent side navigation, an inspector or a tool rail. The order of the sections in the markup does not change, so a screen reader still reads the header first.

The panels are columns of their own here rather than flex items beside the main content, so NavPanelWidth and AsideWidth are applied to the panels themselves, and Gap separates the header and the footer from the main content as well. ReverseNavPanel, Bordered and the sticky sections all follow along.


Header
Main
Footer

Hiding sections

Every section around the main content can be switched off on its own with HideHeader, HideNavPanel, HideAside and HideFooter. The section leaves the markup rather than being hidden with CSS, so it costs nothing while it is off and the sections that stay take the room it used to hold. This is how one layout serves a whole application: the chrome a page does not need is turned off from that page instead of a second layout being built for it. The main section is always rendered, since a page is expected to have exactly one of it.


Header
Main

Section heights

HeaderHeight and FooterHeight pin the two bars to an exact height in pixels instead of letting them grow with their content, which is what keeps the chrome of every page of an application the same size. Both are border-boxes, so the height covers their paddings and borders. The header height doubles as the offset a pinned nav panel or aside uses, which is what the next example relies on.

64px header
Main

Sticky sections

StickyHeader, StickyFooter, StickyNavPanel and StickyAside pin a section in place while the rest of the page scrolls past it. Sticky positioning keeps the sections in the normal flow, so they never overlap the content and need no room reserved for them; it does need a scrolling ancestor to stick within (the box below, or the page itself). That container is the one that scrolls, so it is free to carry an overflow of its own - what breaks the stickiness is an ancestor between it and the sticky section setting an overflow other than visible, which turns that inner element into the scroll container instead. The two panels are pinned HeaderHeight pixels from the top, which is what keeps them clear of a sticky header, and each is given the rest of the viewport with its own scrollbar so a panel taller than the screen stays reachable. Scroll the box to see it.

A pinned header is also what an in-page anchor lands under, so the layout offsets the scroll of its main section by the header height - the skip link of the last example lands on the content rather than behind the header. ZIndex is the stacking order the pinned sections take, which is what decides whether they pass over or under the other layers of the application; the skip link always stays above them.


Header
Scroll me

FullHeight

By default the layout is as tall as its content and as tall as its parent allows, which is what lets it be dropped into a card, a dialog or a box of a fixed height like the ones on this page. FullHeight is what a page level layout wants instead: the middle row grows into the leftover space so the footer of a page with barely any content still sits at the bottom of the screen rather than half way up it. The height follows the browser chrome of a mobile device as it retracts, so the layout is never taller than the part of the screen that is really visible.


Header
Main

ScrollableMain

ScrollableMain keeps the header and the footer where they are and gives the sections of the middle row a scrollport of their own: the chrome of the window never moves and only the content under it scrolls. This is what a sticky section cannot do inside a box that does not scroll with the page, which is why it is the shape an application shell - or a layout inside a dialog - takes. The nav panel and the aside scroll on their own too, so a panel with more items than fit stays reachable without moving the content beside it.

It needs a height to fill, since it is the leftover of that height that becomes the scrollport: FullHeight on a page, or a parent of a definite height like the box below. Turn it off to see the same content push the box itself into scrolling instead.


Header
Scroll me
Footer

Gap & Padding

Gap is the space between the nav panel, the main content and the aside, and Padding is the room around the content of the main section. Both take any CSS length (Gap also takes the two value form of the gap shorthand). The main section is a border-box, so its padding is taken out of the width it already has rather than added to it, which keeps the row from overflowing.

Header
Main

Bordered

Bordered draws the dividers that separate the sections: under the header, above the footer, and between the main content and each of the two panels beside it. The two vertical dividers follow the reading direction and swap sides along with ReverseNavPanel, so they always stay between a panel and the content rather than on the outer edge of the layout.

Header
Main
Footer

Nested

A layout can hold another one - a workspace inside the content of the page, a settings area with a nav panel of its own. A page may only have one main landmark though, so the inner layout is given Nested: its main section renders as a plain element instead of a second main. It keeps its id, its classes and its place as the target of a skip link, and only stops claiming a landmark the page already has.

The other sections need nothing of the sort: a header or a footer stops being a banner or a contentinfo on its own once it sits inside the content of another one, and a page may hold any number of navigation and complementary landmarks.

Header
Nested header
Nested main
Footer

Accessibility

SkipLink renders a link as the first focusable element of the layout that jumps straight to the main section, so a keyboard or screen reader user does not have to walk through the whole header and nav panel on every page. It stays out of sight until it is focused, so it costs a mouse user nothing - press Tab with the focus just before the box below to see it appear. It is drawn above every pinned section, since a focus that lands behind a sticky header is a focus nobody can see. SkipLinkText changes its wording, which is also what a screen reader announces for it.

A page usually holds more than one navigation landmark, and a label is what tells them apart in the landmark list of a screen reader. NavPanelAriaLabel and AsideAriaLabel name those two sections; the words "navigation" and "complementary" are announced already, so the labels should not repeat them.

Skip to the content
Header
Main

Style & Class

Style and Class reach the root element of the layout, while Styles and Classes reach every section of it by name: Root, SkipLink, Header, Main (the middle row), NavPanel, MainContent, Aside and Footer. Note that Main is the row that holds the three middle sections and MainContent is the main section itself, which is what the two are named after in the markup.

Header
Main
Footer

RTL

Set Dir to BitDir.Rtl to lay the sections out right to left. The middle row follows the reading direction, so the nav panel moves to the right and the aside to the left, and the dividers of a bordered layout follow them - no separate RTL markup and no mirrored styles of your own. The direction is cascaded to the content of the layout as well, so the bit components inside it need not be told about it a second time.

سربرگ
محتوا
پاورقی

API

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

BitLayout parameters

Name Type Default value Description
Aside RenderFragment? null The content of the aside section, which sits next to the main content on the side opposite the nav panel. It renders a semantic aside element (the complementary landmark), and is left out of the markup entirely while it is null or HideAside is on.
AsideAriaLabel string? null The accessible label of the aside section, which is what tells more than one complementary landmark apart in the landmark list of a screen reader.
AsideWidth int 0 The width of the aside section in pixels. This is the room the main content leaves for the aside, not a width forced onto the aside itself, so an aside that takes itself out of the flow only has to be given 0 for the main content to span the whole row again.
Bordered bool false Draws divider lines between the sections of the BitLayout. The two vertical dividers follow the reading direction and swap sides along with ReverseNavPanel.
Classes BitLayoutClassStyles? null Custom CSS classes for different parts of the BitLayout.
Footer RenderFragment? null The content of the footer section. It renders a semantic footer element (the contentinfo landmark), and is left out of the markup entirely while it is null or HideFooter is on.
FooterHeight int? null The height of the footer section in pixels, including its paddings and border. When not set, the footer is as tall as its own content.
FullHeight bool false Makes the BitLayout fill at least the height of the viewport, so the footer of a short page still sits at the bottom of the screen. The height follows the browser chrome of a mobile device as it retracts.
FullHeightPanels bool false Makes the nav panel and the aside span the whole height of the BitLayout, with the header and the footer between them rather than above and below them. The panels are columns of their own here, so NavPanelWidth and AsideWidth are applied to the panels themselves.
Gap string? null The space between the nav panel, the main content and the aside (the CSS gap of the middle row). Takes any CSS length or the two value form of the gap shorthand.
Header RenderFragment? null The content of the header section. It renders a semantic header element (the banner landmark), and is left out of the markup entirely while it is null or HideHeader is on.
HeaderHeight int? null The height of the header section in pixels, including its paddings and border. It is also the offset a sticky nav panel or aside pins itself at, so a panel pinned under a sticky header starts right below it.
HideAside bool false Hides the aside section, which is removed from the markup so the main content takes the room it used to reserve for it.
HideFooter bool false Hides the footer section.
HideHeader bool false Hides the header section.
HideNavPanel bool false Hides the nav panel section, which is removed from the markup so the main content takes the room it used to reserve for it.
Main RenderFragment? null The content of the main section. It renders a semantic main element (the main landmark and the target of the skip link), and unlike the other sections it is always rendered.
NavPanel RenderFragment? null The content of the nav panel section. It renders a semantic nav element (the navigation landmark), and is left out of the markup entirely while it is null or HideNavPanel is on.
NavPanelAriaLabel string? null The accessible label of the nav panel section, which is what tells the navigation landmarks of a page apart in the landmark list of a screen reader.
NavPanelWidth int 0 The width of the nav panel section in pixels. This is the room the main content leaves for the panel, not a width forced onto the panel itself, so a panel that collapses to a rail or turns into an overlay drawer only has to be given 0 for the main content to span the whole row again.
Nested bool false Renders the main section as a plain element instead of the main landmark, for a BitLayout nested inside another one, since a page may hold only one main landmark. The section keeps its id, its classes and its place as the target of the skip link.
Padding string? null The padding around the content of the main section. Takes any CSS padding value; the main section is a border-box, so the padding is taken out of the width it already has rather than added to it.
ReverseNavPanel bool false Reverses the position of the nav panel and the aside inside the middle row, which puts the nav panel at the end of the row and the aside at its start.
ScrollableMain bool false Keeps the header and the footer in place and gives the sections of the middle row a scrollport of their own, which is the shape of an application shell. It needs the BitLayout to have a height to fill: FullHeight, or a parent of a definite height.
SkipLink bool false Renders a skip link as the first focusable element of the BitLayout, which jumps to the main section. The link stays out of sight until it is focused.
SkipLinkText string? null The text of the skip link. The default value is "Skip to main content".
StickyAside bool false Enables sticky positioning of the aside, pinned HeaderHeight pixels from the top of the viewport and given the rest of it with its own scrollbar.
StickyFooter bool false Enables sticky positioning of the footer at the bottom of the viewport.
StickyHeader bool false Enables sticky positioning of the header at the top of the viewport.
StickyNavPanel bool false Enables sticky positioning of the nav panel, pinned HeaderHeight pixels from the top of the viewport and given the rest of it with its own scrollbar.
Styles BitLayoutClassStyles? null Custom CSS styles for different parts of the BitLayout.
ZIndex int? null The stacking order of the pinned sections of the BitLayout, which decides whether a sticky section passes over or under the other layers of the application. When not set, they take the base z-index of the theme.

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.

BitLayoutClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitLayout.
SkipLink string? null Custom CSS classes/styles for the skip link of the BitLayout.
Header string? null Custom CSS classes/styles for the header section of the BitLayout.
Main string? null Custom CSS classes/styles for the middle row of the BitLayout that holds the nav panel, the main content and the aside.
NavPanel string? null Custom CSS classes/styles for the nav panel section of the BitLayout.
MainContent string? null Custom CSS classes/styles for the main-content section of the BitLayout.
Aside string? null Custom CSS classes/styles for the aside section of the BitLayout.
Footer string? null Custom CSS classes/styles for the footer section of the BitLayout.

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.