Tutorial about border-property in CSS
Border Overview: All 4 properties
Border-Radius, Border-Width, Border-Style & Border & Color
In order to achieve the look we are going for with our borders we have to know which properties exist and how we use them. In our generator we are offering 4 different properties to customize however you want to, let's have a closer look how they work:
border-radius
border-width
border-style
border-color
The first three of them follow the same schema, we can set one, two, three or four values as seen in the example bellow:
border-width: 2px;
A single value sets all four borders.
border-width: 2px 4px;
The first value sets top and bottom, the second value sets left and right.
border-width: 2px 4px 6px;
The first value sets top, the second left and right and the last on bottom.
border-width: 2px 4px 6px 8px;
Here we are starting from top again and then go clockwise. This way the order of values is top, right, bottom, left.
border-width
As already seen before we can set 1-4 values for our border width to achive different looks. One important thing to note is that we are not tied to be using px as a unit. Instead we also use other units such as rem, em or pt. If the value should be calculated we can also use the CSS calc() function. In case we only want to only set one site we can address this specific value.
The attributes are the following:
- border-top-width: (value)(unit);
- border-right-width: (value)(unit);
- border-bottom-width: (value)(unit);
- border-left-width: (value)(unit);
border-radius
For border-radius we can once again set between one and four values. With the correct syntax even eight are possible :] There is one thing to note tho. Since we are styling our borders we don't have values for top, right, bottom and left. That means
that the the order of the four values has to mean something else. Now we are starting with top-left and then go clockwise again. In this case we can use
px, rem, em, pt, % and calc().
From that we get the following values:
- border-top-left-radius: (value)(unit);
- border-top-right-radius: (value)(unit);
- border-bottom-right-radius: (value)(unit);
- border-bottom-left-radius: (value)(unit);
border-style
This property sets the style of all sides of the given element. In most cases we want to set the same value for all four sides. It is however possible to give each side a different value by adding multiple values after each other.
In total we have 10 values to choose from:
border-style: solid;
Probably the most used value. It displays a single line in the complete border area.
border-style: dotted;
The border consists of many small dots. It depends on the browser how the dots look like exactly. The developer does can not control this.
border-style: dashed;
Behaves similar as dotted. In this case the border consists of many rectangles.
border-style: double;
Shows two lines seperated with a transparent area.
border-style: groove;
The opposit of ridge. The border has a carved appearance.
border-style: ridge;
The opposit of groove. The border has a carved appearance.
border-style: inset;
The opposit of outset. Looks like the border has a shadow which can be used to create a 3D effect.
border-style: outset;
The opposit of inset. Looks like the border has a shadow which can be used to create a 3D effect.
border-style: none;
Element removes the border entirely.
border-color
Last but not least we want to set a color. We can do this by using HEX, RGB(A) or HLS(A) values to one of the following properties:
- border-color: (value)
- border-top-color: (value)
- border-right-color: (value)
- border-bottom-color: (value)
- border-left-color: (value)
For the single property we can again decide if we want to use one to four different values going clockwise: top, right, bottom and left.