Coding Schools


 
Python | C Sharp | Azure AI | HTML | JavaScript | CSS | SQL Server
How to add CSS in HTML
Types of CSS Files
Flex in CSS
Media Query in CSS
CSS - background attribute
CSS - border
css - border-image
CSS align attributes
CSS color attribute
CSS cursor attribute
CSS display attribute
CSS font attributes
CSS height and max-height
CSS width and max-width
CSS padding attributes
CSS margin attributes
CSS mask attributes
CSS overflow attributes
CSS opacity attribute
CSS text decoration attributes
CSS visibility attribute
CSS word attributes
CSS z-index attribute

CSS - border



The border property in CSS is used to set the border around an HTML element. You can customize the border's width, style, color, and radius. The border property is a shorthand for the following individual properties:

  • border-width

  • border-style

  • border-color

  • border-radius

Shorthand Syntax

The shorthand syntax for the border property is:

css
border: [border-width] [border-style] [border-color];

Examples

Here are some examples demonstrating the use of the border property:

  1. Basic Border:

css
div {
    border: 2px solid black;
}
  1. Different Styles:

css
div {
    border-width: 2px;
    border-style: dashed;
    border-color: red;
}
  1. Border Radius:

css
div {
    border: 2px solid black;
    border-radius: 10px;
}
  1. Individual Borders: You can also set individual borders for each side of the element using border-top, border-right, border-bottom, and border-left properties.

css
div {
    border-top: 2px solid black;
    border-right: 2px dashed red;
    border-bottom: 2px solid blue;
    border-left: 2px dotted green;
}

Detailed Example

Here's a detailed example that demonstrates various border properties:

css
.container {
    width: 300px;
    height: 150px;
    border: 5px solid #333; /* Shorthand property */
    border-radius: 15px; /* Rounded corners */
    border-top: 5px solid red; /* Top border */
    border-right: 5px dashed blue; /* Right border */
    border-bottom: 5px double green; /* Bottom border */
    border-left: 5px dotted yellow; /* Left border */
}

In this example:

  • The shorthand border property sets a solid black border with 5px width.

  • The border-radius property sets rounded corners with a radius of 15px.

  • Individual borders for each side are set with different styles and colors.

Additional Notes

  • Border Styles: You can use various border styles such as solid, dotted, dashed, double, groove, ridge, inset, outset, none, and hidden.

  • Box Model: Borders are part of the box model, which also includes padding, content, and margin.

Feel free to ask if you need more specific examples or further explanation on any of these properties!




All rights reserved | Privacy Policy | Sitemap