How to set table width in HTML

青灯夜游
Release: 2021-05-17 15:49:52
Original
16845 people have browsed it

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>
Copy after login

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>
Copy after login

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="max-width:90%">
	<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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!