Home  >  Article  >  Web Front-end  >  How to set table border in html

How to set table border in html

藏色散人
藏色散人Original
2021-04-27 14:46:3547451browse

htmlHow to set the table border: first create an HTML sample file; then define a table through table; finally set it by adding the css code as "tr td,th{border:1px solid red;}" Just the table border.

How to set table border in html

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

Prepare a piece of html code for the table, and use this piece of code to display the browser's default rendering of the table tag. The code is as follows:

<html>
<head>
<title></title>
</head>
<style>
</style>
<body>
<table class="mt">
    <tr>
         <th>col_1</th>
         <th>col_2</th>
         <th>col_3</th>
    </tr>
    <tr>
         <td>value_1</td>
         <td>value_2</td>
        <td>value_3</td>
   </tr>
</table>
</body>
</html>

How to set table border in html

Set the inner border for the table. It can be seen that the default style of the table label has no border. Now we add a border to the table, just add the following code to the style tag:

<style>
tr td,th{
border:1px solid red;
}
</style>

How to set table border in html

How to set table border in html

##Cancel unit The space between cells. In the previous step, although the borders within the rows were set, the space between cells is often not what we want, so we can set it through the following code:

<style>
tr td,th{
border:1px solid red;
}
/*取消table标签中的单元格空白*/
.mt{
 border-collapse:collapse;
}
</style>

How to set table border in html

How to set table border in html

Set the outer border for the table, the code is as follows:

<style>
.mt{
 border-collapse:collapse;
 border:1px solid black; /*设置表格的外边框*/
}
</style>

How to set table border in html

Set the row border, relative to the cell border setting, Row border settings are more common. We only need to use the following code

<style>
 
 
.mt{
 border-collapse:collapse;
 border:1px solid black;
}
/*设置行边框*/
.mt tr{
border-bottom:1px solid black;
}
</style>

How to set table border in html

How to set table border in html

[Recommended learning:

HTML video tutorial]

The above is the detailed content of How to set table border in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn