Home  >  Article  >  Web Front-end  >  How to set borders for tables in css

How to set borders for tables in css

青灯夜游
青灯夜游Original
2021-04-21 14:09:2335471browse

How to set borders for css tables: 1. Use the border attribute to add a border to the table element, the syntax "table{border:width style color;}"; 2. Use the border attribute to add a border to the td element, the syntax " td{border:width style color;}".

How to set borders for tables in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

The default table has no borders

<table>
	<tr>
		<td>商品</td>
		<td>价格</td>
	</tr>
	<tr>
		<td>T恤</td>
		<td>¥100</td>
	</tr>
	<tr>
		<td>牛仔褂</td>
		<td>¥250</td>
	</tr>
	<tr>
		<td>牛仔库</td>
		<td>¥150</td>
	</tr>
</table>

How to set borders for tables in css

We can add borders to the table through css.

Method 1: Set the border only for the table label

Set the border (border) style only for the table label, which will give the outermost table of the table a border. There is no border style generated inside the table.

Grammar:

table{
	border: 1px solid red;
}

Effect picture:

How to set borders for tables in css

##Method 2: Set border for td

Set the border style for the table td. The td within the table object will implement the border style, but the middle td will cause double borders.

Grammar:

td{
border: 1px solid red;
}

Effect picture:

How to set borders for tables in css

If you think the double line effect is not good-looking. You can set:

table {
        border-collapse: collapse;
        
}

Set the merged border model (merged border) for the table (table), the effect picture:

How to set borders for tables in css

(Learning video sharing:

css video tutorial)

The above is the detailed content of How to set borders for tables in css. 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