Home  >  Article  >  Web Front-end  >  How to set the width of td with css

How to set the width of td with css

青灯夜游
青灯夜游Original
2021-04-21 11:47:385345browse

In CSS, you can use the width attribute to set the td width. You only need to set the "width:width value;" style to the td element. The width attribute sets the width of an element, which defines the width of the element's content area, excluding padding, borders, or margins.

How to set the width of td with css

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

Define a tableb table

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
	</head>

	<body>
		<table border="1">
			<tr>
				<th>商品</th>
				<th>价格</th>
			</tr>
			<tr>
				<td>T恤</td>
				<td>¥100</td>
			</tr>
			<tr>
				<td>牛仔褂</td>
				<td>¥250</td>
			</tr>
			<tr>
				<td>牛仔库</td>
				<td>¥150</td>
			</tr>
		</table><br />
	</body> 
</html>

How to set the width of td with css

##How to set the width of td using css?

You can use the width attribute to set the td width, syntax:

td{
    width:100px;
}

Rendering:

How to set the width of td with css

(Learning video sharing:

css video tutorial)

Instructions: The

width attribute sets the width of the element.

Note: The width attribute does not include padding, borders and margins!

Attribute value:


ValueDescriptionautodefault value. The browser can calculate the actual width. Use px, cm and other units to define the width. Defines the width as a percentage based on the width of the containing block (parent element). inheritSpecifies that the value of the width attribute should be inherited from the parent element.
length
%
For more programming-related knowledge, please visit:

Introduction to Programming! !

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