CSS Borders || Bcis Notes

CSS Borders:

The border properties allow you to specify how the border of the box representing an element should look. There are three properties of a border you can change −

  • The border-style specifies whether a border should be solid, dashed line, double line, or one of the other possible values.
  • The border-width specifies the width of a border
  • The border-color specifies the color of a border.

 

1.CSS Border Style:
The border-style property specifies what kind of border to display. The following values are allowed:

  • Dotted – Defines a dotted border
  • Dashed – Defines a dashed border
  • Solid – Defines a solid border
  • Double – Defines a double border
  • Groove – Defines a 3D grooved border. The effect depends on the border-color value
  • Ridge – Defines a 3D ridged border. The effect depends on the border-color value
  • Inset – Defines a 3D inset border. The effect depends on the border-color value
  • Outset – Defines a 3D outset border. The effect depends on the border-color value
  • None – Defines no border
  • Hidden – Defines a hidden border
  • The border-style property can have from one to four values (for the top border, right border, bottom border, and the left border)

CODE:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Result:

 

2. CSS Border-width:
The border-width property allows you to set the width of an element border. The value of this property could be either a length in px, pt or cm or it should be set to thin, medium or thick. You can individually change the width of the bottom, top, left, and right borders of an element using the following properties −

  • border-bottom-width changes the width of the bottom border.
  • border-top-width changes the width of the top border.
  • border-left-width changes the width of the left border.
  • border-right-width changes the width of the right border.

CODE:

 

Result:

 

3. CSS Border-color :
The border-color property allows you to change the color of the border surrounding an element. You can individually change the color of the bottom, left, top and right sides of an element’s border using the properties. The color can be set by-

  • name – specify a color name, like “red”
  • Hex – specify a hex value, like “#ff0000”
  • RGB – specify a RGB value, like “RGB(255,0,0)”
  • transparent

CODE:

 

Result:

CSS Border – Individual Sides
It is possible to specify a different border for each side. In CSS, there are also properties for specifying each of the borders (top, right, bottom, and left):

CODE:

 

Result:

Likewise, here is how it works:

If the border-style property has four values:  border-style: dotted solid double dashed;

  • top border is dotted
  • right border is solid
  • bottom border is double
  • left border is dashed

If the border-style property has three values:  border-style: dotted solid double;

  • top border is dotted
  • right and left borders are solid
  • bottom border is double

If the border-style property has two values:  border-style: dotted solid;

  • top and bottom borders are dotted
  • right and left borders are solid

If the border-style property has one value:  border-style: dotted;

  • all four borders are dotted

However, it also works with border-width and border-color.

 

CSS Border – Shorthand Property
There are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the individual border properties in one property.

The border property is a shorthand property for the following individual border properties:

  • border-width
  • border-style (required)
  • border-color

 

CSS Rounded Borders
The border-radius property is used to add rounded borders to an element:

CODE:

 

Result:

 

You may also like: CSS BACKGROUNDS

 

Leave a Comment

Your email address will not be published. Required fields are marked *