Description:
Headlines.
CSS Border is a property used to add a border around an HTML element. It allows you to specify the color, width, and style of the border. The border property can be used to set all four borders (top, right, bottom, and left) of an element at once, or you can use the individual border properties (border-top, border-right, border-bottom, and border-left) to set each border separately.
The basic syntax for the border property is as follows:
border: width style color;
The width of the border can be set in pixels, ems, or percentage. The style of the border can be set to solid, dotted, dashed, double, groove, ridge, inset, or outset. The color of the border can be set to any valid CSS color value.
For example, the following CSS will create a 2px solid red border around an element:
border: 2px solid red;
In addition to the border property, there are several other border properties that can be used to fine-tune the appearance of your borders. These include:
- border-radius: This property allows you to create rounded corners on your borders. You can specify the radius for each corner separately, or you can set a single radius for all four corners.
- border-collapse: This property controls whether the borders of adjacent table cells are merged or separated.
- border-spacing: This property is used to control the space between adjacent table cells when border-collapse is set to separate.
- box-shadow: This property allows you to add a shadow around an element. You can specify the position, spread, and color of the shadow.
- outline: This property is used to create an outline around an element. It works similarly to the border property, but the outline is drawn outside of the element's box, and it does not take up any space on the page.
In conclusion, the CSS Border property is a powerful tool that allows you to add visual interest and definition to your HTML elements. With its various properties and options, you can create a wide variety of border styles and effects to enhance the design of your website.
Advertise...
Explain in Details.
It is a shorthand property, which means that it can be used to set the values for multiple border-related properties at once.
The properties that can be set using the
border
property are:
-
border-width
: sets the width of the border (can be set in pixels, ems, etc.) -
border-style
: sets the style of the border (e.g. solid, dotted, double, etc.) border-color
: sets the color of the border
The
border
property can be used in the following format: like border: width style color; For example: border: 2px
solid red;
This sets a 2px wide, solid red border around the element.
You can also set different border properties for each side of an element using the following properties:
-
border-top
,border-right
,border-bottom
,border-left
For example:
<style>.test1 {border-top: 2px solid red;border-right: 3px dotted blue;border-bottom: 1px dashed green;border-left: 4px double purple;}</style><div class="test1">This div is for testing...</div>
You can also set different border properties for each corner of an element using the following properties:
-
border-top-left-radius
,border-top-right-radius
,border-bottom-right-radius
,border-bottom-left-radius
For example:
<style>.test2 {border: 5px solid red;border-top-left-radius: 10px;border-top-right-radius: 20px;border-bottom-right-radius: 30px;border-bottom-left-radius: 40px;}</style><div class="test2">This div is for testing...</div>
<style>.test3 {border: 5px solid red;border-radius: 10px 20px 30px 40px;}</style><div class="test3">This div is for testing...</div>
Here are some other border-related properties in CSS:
-
border-collapse
: specifies whether or not table borders should be collapsed
- separate: This is the default value, and it causes each cell to have its own separate borders.
- collapse: This value causes the borders of adjacent cells to collapse into a single border.
-
border-image
: allows you to use an image as the border of an element
- none (no border image)
- url("image.png") (specifying an image file as the border image)
- linear-gradient(to bottom, #ff0000, #0000ff) (using a linear gradient as the border image)
- repeating-linear-gradient(to right, #ff0000, #0000ff) (using a repeating linear gradient as the border image)
- radial-gradient(circle, #ff0000, #0000ff) (using a radial gradient as the border image)
- repeating-radial-gradient(ellipse at center, #ff0000, #0000ff) (using a repeating radial gradient as the border image)
- conic-gradient(from 0deg, #ff0000, #0000ff) (using a conic gradient as the border image)
- repeating-conic-gradient(from 90deg, #ff0000, #0000ff) (using a repeating conic gradient as the border image)
- cross-fade(url("image1.png"), url("image2.png"), 0.5) (using a cross-fade effect between two images as the border image)
- element(#id) (using an SVG element as the border image)
- paint(paintName) (using a named CSS Paint function as the border image)
-
border-spacing
: sets the spacing between cells in a table
- A length value (e.g. "10px", "2em", "1cm")
- A percentage value (e.g. "5%", "20%")
- Two length values separated by a space (e.g. "10px 5px", "2em 1cm")
- Two percentage values separated by a space (e.g. "5% 10%", "20% 30%")
-
border-width
: sets the width of an element's border
- A specific length (e.g. "5px", "1em")
- A percentage of the element's width or height (e.g. "50%")
- The keyword "thin"
- The keyword "medium" (default value)
- The keyword "thick"
- The keyword "initial" (sets the value to its default)
- The keyword "inherit" (inherits the value from the parent element)
-
border-radius
: sets the roundedness of an element's corners
- A single value (e.g. "5px") which will apply the same radius to all four corners of the element.
- Two values (e.g. "5px 10px") which will apply the first value to the top-left and bottom-right corners, and the second value to the top-right and bottom-left corners.
- Three values (e.g. "5px 10px 15px") which will apply the first value to the top-left corner, the second value to the top-right and bottom-left corners, and the third value to the bottom-right corner.
- Four values (e.g. "5px 10px 15px 20px") which will apply the first value to the top-left corner, the second value to the top-right corner, the third value to the bottom-right corner, and the fourth value to the bottom-left corner.
- It's also possible to use percentage values for border-radius.
-
border-top-left-radius
: sets the roundedness of the top-left corner of an element
- A length value (such as 10px, 2em, or 0.5in)
- A percentage value (such as 50%, 25%, or 0%)
- The keyword "inherit" (to inherit the value from the parent element)
- The keyword "initial" (to set the value back to its default value)
- The keyword "unset" (to unset the value and let the browser apply a default value)
-
border-top-right-radius
: sets the roundedness of the top-right corner of an element
- A length value (such as "10px" or "2em")
- A percentage value (such as "50%" or "75%")
- The keyword "inherit" to inherit the value from the parent element
- The keyword "initial" to set the property to its default value
- The keyword "unset" to unset the property and fall back to the inherited or initial value.
-
border-bottom-left-radius
: sets the roundedness of the bottom-left corner of an element
- A length value, such as "10px" or "2em"
- A percentage value, such as "50%"
- The keyword "inherit" to inherit the value from the parent element
- The keyword "initial" to set the property to its default value
- The keyword "unset" to unset the property and revert to the browser's default value.
-
border-bottom-right-radius
: sets the roundedness of the bottom-right corner of an element
- A length value (e.g. "5px", "2em")
- A percentage value (e.g. "50%", "25%")
- The keyword "inherit" (inherits the value from the parent element)
- The keyword "initial" (sets the value to the default value)
- The keyword "unset" (removes any previously set value)
-
border-style
: sets the style of an element's border
- solid - a solid line border
- dotted - a series of small dots forming a border
- dashed - a series of short dashes forming a border
- double - a double line border, with a space in between the two lines
- groove - a 3D border with a groove effect
- ridge - a 3D border with a ridge effect
- inset - a 3D border with an inset effect
- outset - a 3D border with an outset effect
- none - no border is displayed
- hidden - the border is hidden, but still takes up space in the layout
- inherit - inherits the border style from the parent element.
-
border-color
: sets the color of an element's border
- "red" - sets the border color to red
- "#ff0000" - sets the border color to the hex code for red
- "rgb(255, 0, 0)" - sets the border color to the RGB values for red
- "transparent" - sets the border color to be transparent, making it invisible
- "inherit" - sets the border color to inherit the color of the parent element
- "currentColor" - sets the border color to the current color value of the element
- "none" - removes the border color, making the border invisible.
-
border-top
: sets the top border of an element
- A length value (e.g. "2px"): This sets the width of the border in pixels.
- A percentage value (e.g. "10%"): This sets the width of the border as a percentage of the element's width.
- A keyword value (e.g. "thin", "medium", "thick"): This sets the width of the border to a predefined value.
- A color value (e.g. "red", "#ff0000"): This sets the color of the border.
- A shorthand value (e.g. "2px solid red"): This sets the width, style, and color of the border all in one declaration.
- none: This removes the top border from the element.
-
border-right
: sets the right border of an element
- A length value, such as "1px", which sets the width of the border in pixels.
- A percentage value, such as "5%", which sets the width of the border as a percentage of the element's total width.
- A keyword value, such as "thin", "medium", or "thick", which sets the width of the border based on predefined values.
- A color value, such as "red" or "#ff0000", which sets the color of the border.
- A shorthand value, such as "1px solid red", which sets the width, style, and color of the border all in one declaration.
- "none" is used to remove the border from the right side of an element.
-
border-bottom
: sets the bottom border of an element
- A length value, such as "2px" or "1em", which sets the thickness of the border.
- A color value, such as "red" or "#333", which sets the color of the border.
- A border-style value, such as "solid", "dotted", or "double", which sets the style of the border.
- A shorthand value, such as "2px solid red", which sets all three values (thickness, style, and color) at once.
-
border-left
: sets the left border of an element
- A length value (e.g. "5px", "1em") - this sets the width of the left border.
- A thickness keyword (e.g. "thin", "medium", "thick") - this sets the width of the left border based on a predefined thickness.
- A color value (e.g. "red", "#ff0000") - this sets the color of the left border.
- A shorthand value (e.g. "3px solid red") - this sets the width, style, and color of the left border all at once. The order is width, style, color.
- "none" - this removes any left border that may have been previously set.
- "initial" - this sets the left border to its default value.
- "inherit" - this inherits the left border value from the parent element.
Here are some additional CSS properties related to borders:
-
border-block-end
: sets the border properties for the end edge of a block-level element
- "thin" - a thin border
- "medium" - a medium-width border
- "thick" - a thick border
- <length> - a specific length value, such as "5px"
- "initial" - sets the border to its default value
- "inherit" - inherits the border value from its parent element
- Additionally, you can specify the style of the border using keywords such as "solid", "dotted", "dashed", "double", "groove", "ridge", "inset", "outset", and "none".
-
border-block-start
: sets the border properties for the start edge of a block-level element
- none: No border is applied to the start edge of the element
- <border-width> <border-style> <border-color>: This value allows you to set the width, style, and color of the border for the start edge. For example, "2px solid red" would create a 2px red solid border.
- inherit: The border-block-start property inherits the value of the parent element's border-block-start property.
-
border-inline-end
: sets the border properties for the end edge of an inline element
- A specific length (e.g. "2px")
- A percentage (e.g. "5%")
- The keyword "medium" (which sets the border width to a medium value)
- The keyword "thin" (which sets the border width to a thin value)
- The keyword "thick" (which sets the border width to a thick value)
- The keyword "none" (which removes the border)
- A combination of the above values with a separator (e.g. "2px solid blue") where the first value represents the width, second value represents the style, and the third value represents the color.
-
border-inline-start
: sets the border properties for the start edge of an inline element
- A length value (e.g. "1px") sets the width of the border.
- A keyword value (e.g. "thin", "medium", "thick") sets the width of the border.
- A color value (e.g. "red", "#ff0000") sets the color of the border.
- A keyword value (e.g. "solid", "dotted", "dashed") sets the style of the border.
- "none" disables the border on the start side of the inline element.
- "initial" sets the property to its default value.
- "inherit" inherits the property from the parent element.
-
border-block-color
: sets the color of the block-level element's border
- A valid color value such as "red", "rgb(255,0,0)", or "#ff0000"
- The keyword "transparent" which sets the border color to be transparent
- The keyword "currentColor" which sets the border color to the same as the element's current text color
-
border-inline-color
: sets the color of the inline element's border
- A color keyword (e.g. "red", "blue", "green")
- A hex code (e.g. "#ff0000", "#0000ff", "#00ff00")
- An RGB or RGBA value (e.g. "rgb(255, 0, 0)", "rgba(0, 0, 255, 0.5)")
- The keyword "transparent"
- border-inline-width: 2px;
- border-inline-style: solid;
- border-inline-color: red;
border-inline-color
property is not widely
supported in current browsers. Instead of using it, you can use the
border-color property.
-
border-block-width
: sets the width of the block-level element's border
- thin: a thin border (equivalent to 1px in most browsers)
- medium: a medium border (equivalent to 3px in most browsers)
- thick: a thick border (equivalent to 5px in most browsers)
- length: a specific length value in units such as px, em, or rem
- initial: sets the property to its default value
- inherit: inherits the value from the parent element
border-block-width
is not yet
supported by all major web browsers, so it's better to use the
border-top-width, border-right-width, border-bottom-width, and
border-left-width properties for cross-browser compatibility.
-
border-inline-width
: sets the width of the inline element's border
- thin: a thin border (equivalent to 1px in most browsers)
- medium: a medium border (equivalent to 3px in most browsers)
- thick: a thick border (equivalent to 5px in most browsers)
- length: a specific length value in units such as px, em, or rem
- initial: sets the property to its default value
- inherit: inherits the value from the parent element
border-inline-width
is not yet
supported by all major web browsers, so it's better to use the
border-top-width,
border-right-width,
border-bottom-width,
and
border-left-width
properties for cross-browser compatibility.
-
border-block-style
: sets the style of the block-level element's border
The CSS property border-block-style
sets the style of
the block-level borders of an element. It can take the following values:
none
: no bordersolid
: a solid borderdotted
: a border with small dotsdashed
: a border with short dashes-
double
: a double border, with the width of the border being the sum of the two single borders groove
: a 3D grooved borderridge
: a 3D ridged borderinset
: a 3D inset borderoutset
: a 3D outset borderinitial
: sets the property to its default valueinherit
: inherits the value from the parent element
border-block-style
is not
yet supported by all major web browsers, so it's better to use
the border-top-style
, border-right-style
, border-bottom-style
,
and border-left-style
properties for cross-browser
compatibility.
-
border-inline-style
: sets the style of the inline element's border
The CSS property border-inline-style
sets the style
of the inline-level borders of an element. It can take the following values:
none
: no border-
hidden
: same as "none", but has different behavior in tables dotted
: a series of round dotsdashed
: a series of short dashessolid
: a solid borderdouble
: two parallel solid linesgroove
: a 3D inset borderridge
: a 3D outset borderinset
: a 3D inset borderoutset
: a 3D outset borderinitial
: sets the property to its default valueinherit
: inherits the value from the parent element
border-inline-style
is not
yet supported by all major web browsers, so it's better to use
the border-top-style
, border-right-style
, border-bottom-style
,
and border-left-style
properties for cross-browser
compatibility.
These properties are relatively new and not supported by all browsers, so you should check for browser compatibility before using them.
0 Comments