Home > Article > Web Front-end > How to specify double borders using CSS?
We know that CSS is a rule-based style sheet language used to design and customize web pages. They are used to specify how html elements are formatted and displayed on the screen. One style we often use is to add or modify the border of an element. This can be achieved by using the CSS 'border property'.
"Border" is an abbreviated way of specifying a border around an element, by specifying the border width, style, and color. Therefore, we can say that the border property actually consists of the following three properties.
Border Color - It sets the color of the border, falling back to the current color if not present.
Border-style − It specifies the border style being used, falling back to none if it does not exist.
Border-width - This determines the thickness of the border, default is "medium"
We can also specify the width, style and color of each side of the border individually. Note that it is not an inheritable property, which means that if the container element has a border around it, the child elements will not have a border unless specified.
We can use one, two or all three properties to specify the border. Any value we don't specify will have its default/initial value as its value.
An example of a border using all three properties is given below.
<!DOCTYPE html> <html lang="en"> <head> <title>Border and its styling</title> <style> div { width: 100%; height: 200px; align-content: center; justify-content: center; } #box1 { background-color: antiquewhite; border: 2px solid black; } #box2 { background-color: aquamarine; border: dashed blue; } #box3 { background-color: blanchedalmond; border: red; } #box4 { background-color: beige; border: 1px rebeccapurple; } </style> </head> <body> <div id="box1">Black 2px solid border</div> <div id="box2">Blue dashed border</div> <div id="box3">No visible border</div> <div id="box4">No visible border</div> </body> </html>
We can see that each style has a different effect on the border of the element.
Now that we have learned the basics of using the border property in CSS, we will start solving the question "How to specify a double border using CSS". Let’s take a brief look at what the border-style property is, what you can do with it, and how to use it to solve our problem.
We have discussed above that the border-style attribute controls the border style applied to elements in CSS. The border-style attribute is used to control how the border line is displayed on the web page. This is also a shorthand property, consisting of the bottom, left, right and top style properties.
We can specify the border-style attribute using one, two, three, or all four values.
If we only use one value, this property has the effect of applying the same style to all border lines.
When we use two values, the first style will be applied to the top and bottom of the border, while the second style will be applied to the left and right parts of the border.
李>When three values are specified, the first style will be applied to the top, the second style will be applied to the left and right sections, and the last style will be applied to the bottom.
If we specify all four values, the order in which the styles are applied will be top, right, bottom, and left (i.e. clockwise from top).
Now let's see what possible values we can give to this property.
No
hide
Dotted
dotted line
solid
pair
Groove
Ridge
insert
Outset
starting point
After looking at these values, we can see that by using "double" as the value of the border-style property, we can achieve the effect of double borders.
An example of using the border-style attribute to specify a double border is given below.
<!DOCTYPE html> <html> <head> <style> body { background-color: beige; text-align: center; } h1.doubleApplied { border-width: 5px; border-style: double; Border-color: blue; } h1.double2Applied { border-width: 15px; border-style: double; Border-color: blue; } h1.double3Applied { border-width: 20px; border-style: double; Border-color: blue } </style> </head> <body> <h1 class="doubleApplied">This has double styled border with thinnest border</h1> <h1 class="double2Applied">This has double styled border applied with slightly thick border than previous box.</h1> <h1 class="double3Applied">This has double styled border applied with the thickest border</h1> </body> </html>
We can see that by using double as the value, all elements have a double border of varying thickness around them.
In summary, specifying double borders using CSS is a simple task. You just need to use the border-style attribute and set it to double. This will draw two lines on each side of the element, giving your page a unique and stylish look. Additionally, you can use other properties such as "border-width" and "border-color" to customize the color, size, and other properties of these borders. With practice, you'll soon be able to create stunning designs with borders.
The above is the detailed content of How to specify double borders using CSS?. For more information, please follow other related articles on the PHP Chinese website!