Sunday, 20 September 2015

CSS Border

CSS Border

The CSS border is a shorthand property used to set the border on an element.
The CSS border properties are use to specify the style, color and size of the border of an element. The CSS border properties are given below
  • border-style
  • border-color
  • border-width
  • border-radius

1) CSS border-style

The Border style property is used to specify the border type which you want to display on the web page.
There are some border style values which are used with border-style property to define a border.
ValueDescription
noneIt doesn't define any border.
dottedIt is used to define a dotted border.
dashedIt is used to define a dashed border.
solidIt is used to define a solid border.
doubleIt defines two borders wIth the same border-width value.
grooveIt defines a 3d grooved border. effect is generated according to border-color value.
ridgeIt defines a 3d ridged border. effect is generated according to border-color value.
insetIt defines a 3d inset border. effect is generated according to border-color value.
outsetIt defines a 3d outset border. effect is generated according to border-color value.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <style>  
  5. p.none {border-style: none;}  
  6. p.dotted {border-style: dotted;}  
  7. p.dashed {border-style: dashed;}  
  8. p.solid {border-style: solid;}  
  9. p.double {border-style: double;}  
  10. p.groove {border-style: groove;}  
  11. p.ridge {border-style: ridge;}  
  12. p.inset {border-style: inset;}  
  13. p.outset {border-style: outset;}  
  14. p.hidden {border-style: hidden;}  
  15. </style>  
  16. </head>  
  17. <body>  
  18. <p class="none">No border.</p>  
  19. <p class="dotted">A dotted border.</p>  
  20. <p class="dashed">A dashed border.</p>  
  21. <p class="solid">A solid border.</p>  
  22. <p class="double">A double border.</p>  
  23. <p class="groove">A groove border.</p>  
  24. <p class="ridge">A ridge border.</p>  
  25. <p class="inset">An inset border.</p>  
  26. <p class="outset">An outset border.</p>  
  27. <p class="hidden">A hidden border.</p>  
  28. </body>  
  29. </html>  

Output:
No border.
A dotted border.
A dashed border.
A solid border.
A double border.
A groove border.
A ridge border.
An inset border.
An outset border.
A hidden border.

2) CSS border-width

The border-width property is used to set the border's width. It is set in pixels. You can also use the one of the three pre-defined values, thin, medium or thick to set the width of the border.

Note: The border-width property is not used alone. It is always used with other border properties like "border-style" property to set the border first otherwise it will not work.

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <style>  
  5. p.one {  
  6.     border-style: solid;  
  7.     border-width: 5px;  
  8. }  
  9. p.two {  
  10.     border-style: solid;  
  11.     border-width: medium;  
  12. }  
  13. p.three {  
  14.     border-style: solid;  
  15.     border-width: 1px;  
  16. }  
  17. </style>  
  18. </head>  
  19. <body>  
  20. <p class="one">Write your text here.</p>  
  21. <p class="two">Write your text here.</p>  
  22. <p class="three">Write your text here.</p>  
  23. </body>  
  24. </html>  


3) CSS border-color

There are three methods to set the color of the border.
  • Name: It specifies the color name. For example: "red".
  • RGB: It specifies the RGB value of the color. For example: "rgb(255,0,0)".
  • Hex: It specifies the hex value of the color. For example: "#ff0000".
There is also a border color named "transparent". If the border color is not set it is inherited from the color property of the element.

Note: The border-color property is not used alone. It is always used with other border properties like "border-style" property to set the border first otherwise it will not work.

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <style>  
  5. p.one {  
  6.     border-style: solid;  
  7.     border-color: red;  
  8. }  
  9. p.two {  
  10.     border-style: solid;  
  11.     border-color: #98bf21;  
  12. }   
  13. </style>  
  14. </head>  
  15. <body>  
  16. <p class="one">This is a solid red border</p>  
  17. <p class="two">This is a solid green border</p>  
  18. </body>  
  19. </html>  

No comments:

Post a Comment