Skip to content

Border ​

Brief Introduction ​

The Border component is used to add border styles to elements, supporting multiple border styles, colors, and directions. You can use <MYBorder></MYBorder> or <MYBorder /> to configure the border.

About Basic Borders ​

borderStyle ​

Use borderStyle to define the basic style of the border.
The default color is black; here we use borderColor to set a clear color.

Code Demo
Border is solid
Border is dashed
Border is dotted
展开代码

borderWidth ​

Use borderWidth to define the thickness of the border. Default is 1px. Here we use borderColor to set a clear color.

Code Demo
Thickness is 2px
Thickness is 4vh
Thickness is 6rem
Thickness is 8vw
展开代码

borderColor ​

Use borderColor to define the color of the border. Default is black; here we use borderStyle="dashed" together.

Code Demo
Red border
Blue border
Red border
Blue border
展开代码

Border Directions ​

You can set a separate color for each direction of the border. If you set a color for a single direction, the default border color becomes white.

Code Demo
Top, bottom, left, right: red, blue, green, yellow respectively
展开代码

Center Content ​

Use center to center the content inside the border. Here we use borderColor to set a clear color.

Code Demo
Centered text
展开代码

Rounded Corners ​

Use the rounded prop to add rounded corners to the border. Here we use borderColor to set a clear color. For better visualization, we also use paddingText to move the text.

Code Demo
This is a rounded border
展开代码

Circle Shape ​

Use the circular prop to turn the border into a circle. Here we use borderColor to set a clear color. For better visualization, we also use paddingText to move the text.

Code Demo
This is a circular border
展开代码

Background Color Inside Border ​

Use colorBackground to set the background color inside the border.

Code Demo
This is a border with background color
展开代码

Text Color Inside Border ​

Use textColor to set the color of the text inside the border.

Code Demo
This is a border with red text
展开代码

Shadow ​

Use boxShadow to add a shadow effect to the border. Its usage is the same as the native CSS box-shadow property.

Code Demo
This is a border with shadow
展开代码

Custom Width and Height ​

Use the width and height props to set the dimensions. For better visualization, we also use paddingText to move the text and borderColor to set a color. Width and height can be used independently.

Code Demo
100px high, 300px wide
展开代码

Spacing Between Content and Border ​

Use paddingText to set the distance between the content and the border. It works like the native CSS padding property, and its usage is the same as CSS padding.

Code Demo
paddingText is 100px
展开代码

Finally, here is a combination of multiple props:

Code Demo
Combined usage
展开代码

Note:

· If you set colors for border directions, borderStyle and borderWidth will be overridden, and borderStyle will no longer take effect.
· If both borderColor and directional color props are set, the directional colors will override borderColor. Therefore, use only one style at a time.
· If circular is set, rounded will not take effect. circular and rounded can only be used one at a time.

API Reference ​

Props ​

PropDescriptionTypeOptionsDefault
borderStyleBorder stylestringsolid/dashed/dotted/doublesolid
borderWidthBorder thicknessstringpx/rem/vh/vw1px
borderColorBorder colorstringHex or named color—
topColorTop border colorstringHex or named color—
bottomColorBottom border colorstringHex or named color—
leftColorLeft border colorstringHex or named color—
rightColorRight border colorstringHex or named color—
roundedRounded cornersboolean—false
circularCircle shapeboolean—false
colorBackgroundBackground colorstringHex or named color—
textColorText colorstringHex or named color—
boxShadowShadow effectstringAny CSS shadow format—
widthBorder widthstringpx/rem/vh/vw—
heightBorder heightstringpx/rem/vh/vw—
paddingTextSpacing between content and borderstringpx/rem/vh/vw—
tagRendered HTML tagstringAny HTML tagdiv

Type Definitions ​

typescript
interface BorderProps {
  borderStyle?: 'solid' | 'dashed' | 'dotted' | 'double';
  borderWidth?: string;
  borderColor?: string;
  topColor?: string;
  bottomColor?: string;
  leftColor?: string;
  rightColor?: string;
  rounded?: boolean;
  circular?: boolean;
  colorBackground?: string;
  textColor?: string;
  boxShadow?: string;
  width?: string;
  height?: string;
  paddingText?: string;
  tag?: string;
}

Released under the MIT License.