Tonic UI

Box

The Box component serves as a wrapper component for most of the CSS utility needs. It allows you to control styling using style props to build a variety of components.

Dark Mode
Box
Tonic UI

Import

Usage

My component
EDITABLE EXAMPLE

The as prop and custom component

By default, the Box component renders a div element. There might be cases where you want to render a different element, you can use the as prop to do that.

EDITABLE EXAMPLE

Using pseudo props

Box also provides useful props to style common CSS pseudo-class and pseudo-element selectors.

A pseudo-class selector targets elements depending on their state rather than on information from the document tree. For example, the selector :hover matches when the user interacts with an element with a pointing device, but does not necessary activate it.

A pseudo-element selector applies styles to parts of your document content in scenarios where there isn't a specific HTML element to select. For example, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property.

NameSelector
_active&:active
_checked&:checked
_disabled&:disabled
_empty&:empty
_enabled&:enabled
_firstChild&:first-child
_firstOfType&:first-of-type
_fullscreen&:fullscreen
_focus&:focus
_focusWithin&:focus-within
_hover&:hover
_indeterminate&:indeterminate
_invalid&:invalid
_lastChild&:last-child
_lastOfType&:last-of-type
_nthOfType&:nth-of-type()
_readOnly&:read-only
_visited&:visited
__after&::after
__backdrop&::backdrop
__before&::before
__cue&::cue
__firstLetter&::first-letter
__firstLine&::first-line
__placeholder&::placeholder
__selection&::selection

:hover

Add the _hover prop to apply style props on hover.

EDITABLE EXAMPLE

:active

Add the _active prop to apply style props on active.

EDITABLE EXAMPLE

:focus

Add the _focus prop to apply style props on focus.

EDITABLE EXAMPLE

:disabled

Add the _disabled prop to style an element which is disabled.

EDITABLE EXAMPLE

:visited

Add the _visited prop to style a visited link.

EDITABLE EXAMPLE

:first-child

Add the _firstChild prop to style an element that is the first element among its siblings.

One
Two
Three
EDITABLE EXAMPLE

:last-child

Add the _lastChild prop to style an element that is the last element among its siblings.

One
Two
Three
EDITABLE EXAMPLE

:nth-of-type()

Add the _nthOfType prop to match elements of a given type, based on their position among a group of siblings. The value can be represented as an array or an object in the following form:

This element isn't counted.

1st paragraph.

2nd paragraph.

This element isn't counted.

3rd paragraph.

4th paragraph.

EDITABLE EXAMPLE

:nth-of-type(odd)

One
Two
Three
Four
Five
EDITABLE EXAMPLE

:nth-of-type(even)

One
Two
Three
Four
Five
EDITABLE EXAMPLE

Examples

Let's take a look at some examples of how to use Box to style elements.

Responsive layout

240
2 / 01:20.592
Taiwan Leave System
REC
A
B
339
2 / 01:24.036
404 Not Found
REC
A
B
003
2 / 01:37.890
ShowMeThe$$
REC
A
B
207
1 / 00:49.211
Dragon Rider
REC
A
B
456
0 / 00:00.000
BumbleBee
REC
A
B
EDITABLE EXAMPLE