Divider
<sc-divider> | ScDivider
Dividers are used to visually separate or group elements.
<sc-divider></sc-divider>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; const App = () => <ScDivider />;
Examples
Width
Use the --width
custom property to change the width of the divider.
<sc-divider style="--width: 4px;"></sc-divider>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; const App = () => <ScDivider style={{ '--width': '4px' }} />;
Color
Use the --color
custom property to change the color of the divider.
<sc-divider style="--color: tomato;"></sc-divider>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; const App = () => <ScDivider style={{ '--color': 'tomato' }} />;
Spacing
Use the --spacing
custom property to change the amount of space between the divider and it’s
neighboring elements.
<div style="text-align: center;"> Above <sc-divider style="--spacing: 2rem;"></sc-divider> Below </div>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; const App = () => ( <> Above <ScDivider style={{ '--spacing': '2rem' }} /> Below </> );
Vertical
Add the vertical
attribute to draw the divider in a vertical orientation. The divider will span
the full height of its container. Vertical dividers work especially well inside of a flex container.
<div style="display: flex; align-items: center; height: 2rem;"> First <sc-divider vertical></sc-divider> Middle <sc-divider vertical></sc-divider> Last </div>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; const App = () => ( <div style={{ display: 'flex', alignItems: 'center', height: '2rem' }} > First <ScDivider vertical /> Middle <ScDivider vertical /> Last </div> );
Menu Dividers
Use dividers in menus to visually group menu items.
<sc-menu style="max-width: 200px;"> <sc-menu-item value="1">Option 1</sc-menu-item> <sc-menu-item value="2">Option 2</sc-menu-item> <sc-menu-item value="3">Option 3</sc-menu-item> <sc-divider></sc-divider> <sc-menu-item value="4">Option 4</sc-menu-item> <sc-menu-item value="5">Option 5</sc-menu-item> <sc-menu-item value="6">Option 6</sc-menu-item> </sc-menu>
import ScDivider from '@styledc-dev/styledc/dist/react/divider'; import ScMenu from '@styledc-dev/styledc/dist/react/menu'; import ScMenuItem from '@styledc-dev/styledc/dist/react/menu-item'; const App = () => ( <ScMenu style={{ maxWidth: '200px' }}> <ScMenuItem value="1">Option 1</ScMenuItem> <ScMenuItem value="2">Option 2</ScMenuItem> <ScMenuItem value="3">Option 3</ScMenuItem> <sc-divider /> <ScMenuItem value="4">Option 4</ScMenuItem> <ScMenuItem value="5">Option 5</ScMenuItem> <ScMenuItem value="6">Option 6</ScMenuItem> </ScMenu> );
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/divider/divider.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/divider/divider.js';
To import this component using a bundler:
import '@styledc-dev/styledc/dist/components/divider/divider.js';
To import this component as a React component:
import ScDivider from '@styledc-dev/styledc/dist/react/divider';
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
vertical
|
Draws the divider in a vertical orientation. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Custom Properties
Name | Description | Default |
---|---|---|
--color |
The color of the divider. | |
--width |
The width of the divider. | |
--spacing |
The spacing of the divider. |
Learn more about customizing CSS custom properties.