English 中文(简体)
CSS - Borders
  • 时间:2024-12-22

CSS - Borders


Previous Page Next Page  

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-color specifies the color of a border.

    The border-style specifies whether a border should be sopd, dashed pne, double pne, or one of the other possible values.

    The border-width specifies the width of a border.

Now, we will see how to use these properties with examples.

The border-color Property

The border-color property allows you to change the color of the border surrounding an element. You can inspanidually change the color of the bottom, left, top and right sides of an element s border using the properties −

    border-bottom-color changes the color of bottom border.

    border-top-color changes the color of top border.

    border-left-color changes the color of left border.

    border-right-color changes the color of right border.

The following example shows the effect of all these properties −

<html>
   <head>
      <style type = "text/css">
         p.example1 {
            border:1px sopd;
            border-bottom-color:#009900; /* Green */
            border-top-color:#FF0000;    /* Red */
            border-left-color:#330000;   /* Black */
            border-right-color:#0000CC;  /* Blue */
         }
         p.example2 {
            border:1px sopd;
            border-color:#009900;        /* Green */
         }
      </style>
   </head>

   <body>
      <p class = "example1">
         This example is showing all borders in different colors.
      </p>
      
      <p class = "example2">
         This example is showing all borders in green color only.
      </p>
   </body>
</html> 

It will produce the following result −