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

  • 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.

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

The border-color Property:

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

This will produce following result:

This example is showing all borders in different colors.

This example is showing all borders in green color only.

To Become more comfortable - Do Online Practice

The border-style Property:

  • ridge: Border looks the opposite of groove.

  • inset: Border makes the box look like it is embedded in the page.

  • outset: Border makes the box look like it is coming out of the canvas.

  • hidden: Same as none, except in terms of border-conflict resolution for table elements.

  • You can individually change the style of the bottom, left, top, and right borders of an element using following properties:

    • border-bottom-style changes the style of bottom border.

    • border-top-style changes the style of top border.

    • border-left-style changes the style of left border.

    • border-right-style changes the style of right border.

    Following is the example to show all these border styles:

    <p style="border-width:4px; border-style:none;">
    This is a border with none width.
    </p>
    <p style="border-width:4px; border-style:solid;">
    This is a solid border.
    </p>
    <p style="border-width:4px; border-style:dashed;">
    This is a dahsed border.
    </p>
    <p style="border-width:4px; border-style:double;">
    This is a double border.
    </p>
    <p style="border-width:4px; border-style:groove;">
    This is a groove border.
    </p>
    <p style="border-width:4px; border-style:ridge">
    This is aridge  border.
    </p>
    <p style="border-width:4px; border-style:inset;">
    This is a inset border.
    </p>
    <p style="border-width:4px; border-style:outset;">
    This is a outset border.
    </p>
    <p style="border-width:4px; border-style:hidden;">
    This is a hidden border.
    </p>
    <p style="border-width:4px; 
                 border-top-style:solid;
                 border-bottom-style:dashed;
                 border-left-style:groove;
                 border-right-style:double;">
    This is a a border with four different styles.
    </p>
    

    This will produce following result:

    This is a border with none width.

    This is a solid border.

    This is a dahsed border.

    This is a double border.

    This is a groove border.

    This is aridge border.

    This is a inset border.

    This is a outset border.

    This is a hidden border.

    This is a a border with four different styles.

    To Become more comfortable - Do Online Practice

    The border-width Property:

    Following is the example to show all these border width:

    <p style="border-width:4px; border-style:solid;">
    This is a solid border whose width is 4px.
    </p>
    <p style="border-width:4pt; border-style:solid;">
    This is a solid border whose width is 4pt.
    </p>
    <p style="border-width:thin; border-style:solid;">
    This is a solid border whose width is thin.
    </p>
    <p style="border-width:medium; border-style:solid;">
    This is a solid border whose width is medium;
    </p>
    <p style="border-width:thick; border-style:solid;">
    This is a solid border whose width is thick.
    </p>
    <p style="border-bottom-width:4px;
                 border-top-width:10px;
                 border-left-width: 2px;
                 border-right-width:15px;
                 border-style:solid;">
    This is a a border with four different width.
    </p>
    

    This will produce following result:

    This is a solid border whose width is 4px.

    This is a solid border whose width is 4pt.

    This is a solid border whose width is thin.

    This is a solid border whose width is medium;

    This is a solid border whose width is thick.

    This is a a border with four different width.

    To Become more comfortable - Do Online Practice

    Border Properties Using Shorthand:

    This will produce following result:

    This example is showing shorthand property for border.

    To Become more comfortable - Do Online Practice

    previous next Printer Friendly


      

    Advertisements



    Advertisements