How to apply border inside a table

Configurare noua (How To)

Situatie

There are two ways to apply border inside the table in HTML.

  • Only using HTML
  • Using HTML and CSS

Only Using HTML: In this case, we will use rules attribute of table. Rules is the attribute in HTML table which allows user to display only inside borders of the table which can be choosen among only rows, cols or all.

Solutie

<!-- Table contains border from
        inside only -->
<!DOCTYPE html>
<html>
<head>
    <title>Table In HTML</title>
</head>
 
<body>
    <h2>Table having rules="rows":</h2>
    <table rules="rows">
         
        <!--table containing only
            border of rows-->
        <tr>
            <th>Roll Number</th>
            <th>Name Of Geek</th>
            <th>Marks</th>
        </tr>
        <tr>
            <td>01</td>
            <td>Geek 01</td>
            <td>100</td>
        </tr>
        <tr>
            <td>02</td>
            <td>Geek 02</td>
            <td>95</td>
        </tr>
        <tr>
            <td>03</td>
            <td>Geek 03</td>
            <td>90</td>
        </tr>
    </table>
     
    <br>
    <hr><hr>
    <br>
     
    <h2>Table having rules="cols":</h2>
     
    <!--table containing only
        border of columns-->
    <table rules="cols">
        <tr>
            <th>Roll Number</th>
            <th>Name Of Geek</th>
            <th>Marks</th>
        </tr>
        <tr>
            <td>01</td>
            <td>Geek 01</td>
            <td>100</td>
        </tr>
        <tr>
            <td>02</td>
            <td>Geek 02</td>
            <td>95</td>
        </tr>
        <tr>
            <td>03</td>
            <td>Geek 03</td>
            <td>90</td>
        </tr>
    </table>
     
    <br>
    <hr><hr>
    <br>
     
    <h2>Table having rules="all":</h2>
     
    <!--table containing borders of
        both row and column-->
    <table rules="all">
        <tr>
            <th>Roll Number</th>
            <th>Name Of Geek</th>
            <th>Marks</th>
        </tr>
        <tr>
            <td>01</td>
            <td>Geek 01</td>
            <td>100</td>
        </tr>
        <tr>
            <td>02</td>
            <td>Geek 02</td>
            <td>95</td>
        </tr>
        <tr>
            <td>03</td>
            <td>Geek 03</td>
            <td>90</td>
        </tr>
    </table>
</body>
 
</html>
Output:

Tip solutie

Permanent

Voteaza

(9 din 20 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?