"; 2. Use the style attribute in the table tag and add the "width: width value;" style."/> "; 2. Use the style attribute in the table tag and add the "width: width value;" style.">

Home >Web Front-end >HTML Tutorial >How to set table width in HTML

How to set table width in HTML

青灯夜游
青灯夜游Original
2021-05-17 15:49:0416911browse

How to set the table width in HTML: 1. Directly use the width attribute of the table tag, with the syntax "

"; 2. Use the style attribute in the table tag and add "width :width value;" style.

How to set table width in HTML

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

After adding a border to the table tag using the border attribute, the default width is determined by the content inside:

<table border="1">
			<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>

Rendering:

How to set table width in HTML

Then How to set table width?

Method 1: Use the width attribute of the table tag

<table border="1" width="200">
	<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>

Rendering:

How to set table width in HTML

Method 2: Use the style attribute to add the "width: width value;" style

<table border="1" style="width: 250px;">
	<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>

Rendering:

How to set table width in HTML

( Learning video sharing: css video tutorial, "html video tutorial")

The above is the detailed content of How to set table width 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