CSS borders create boundaries around webpage elements. They consist of border-width, border-style, and border-color.
Shorthand property border combines all three, allowing precise control over element layout and design.
Basics of the border property
div {
border: 1px solid #000;
width: 200px;
height: 100px;
}
This applies a solid black border with a width of 1 pixel around all <div> elements.
div {
border: 2px dashed blue;
width: 200px;
height: 100px;
}
This example sets a dashed blue border with a width of 2 pixels for all <div> elements.
div {
border-top: 1px solid red;
border-right: 2px dashed green;
border-bottom: 3px dotted blue;
border-left: 4px double orange;
width: 200px;
height: 100px;
}
This creates a different border style and color for each side of all <div> elements, with red on top, green on the right, blue at the bottom, and orange on the left.
div {
border: 2px dashed blue;
border-radius: 10px;
width: 200px;
height: 100px;
}
The border-radius property adds rounded corners to all <div> elements, making their corners smooth.
div {
border: 2px dashed blue;
border-width: 1px 2px 3px 4px;
border-style: solid dashed dotted double;
border-color: red green blue orange;
width: 200px;
height: 100px;
}
This example separates the border properties into individual declarations for more control over each side of all <div> elements. The top border is red and solid, the right border is green and dashed, the bottom border is blue and dotted, and the left border is orange and double.
div {
border: none;
width: 200px;
height: 100px;
}
This removes all borders from all <div> elements.
By following this modified tutorial, you can create various border styles and customize the appearance of borders for all HTML elements using CSS.