search
HomeWeb Front-endFront-end Q&AWhat are the table attributes of css3

css3 table attributes: 1. border-collapse; 2. border-spacing; 3. caption-side; 4. empty-cells; 5. table-layout; 6. width; 7. padding; 8. text-align etc.

What are the table attributes of css3

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

1.CSS table

Using CSS can make HTML tables more beautiful. To specify the CSS table border, use the border attribute.

Abbreviated border properties set all border properties in one declaration.

The properties that can be set are (in order): border-width, border-style, border-color. (That is, the width of the border, the style of the border, and the color of the border)

It doesn't matter if one of the above values ​​is missing, for example, border: #FF0000; is allowed.

1.1 border attribute

##ValueDescriptionSpecify the width of the borderSpecify the style of the border##border-color
border-width
border-style
Specify the color of the border

1.2 border-width attribute

Valuethinmediumthicklength
Description
Define thin borders.
Default. Define a medium border.
Define a thick border.
Allows you to customize the width of the border.

1.3 border-style attribute

valuenonehiddendotteddashedsoliddoublegrooveridgeinsetoutset
Description
Define no border.
Same as "none". Except when applied to tables, for which hidden is used to resolve border conflicts.
Define dotted border. Renders as a solid line in most browsers.
Define dashed line. Renders as a solid line in most browsers.
Define a solid line.
Define double line. The width of the double line is equal to the value of border-width.
Define the 3D groove border. The effect depends on the value of border-color.
Define the 3D ridge border. The effect depends on the value of border-color.
Define the 3D inset border. The effect depends on the value of border-color.
Define the 3D outset border. The effect depends on the value of border-color.

1.4 border-color attribute

valuecolortransparent small example:
Description
Specifies the background color.
Specifies that the border color should be transparent. This is the default
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>CSS简单学习</title>
		<style type="text/css">
			table,th,td {
				border: 1px solid black;
			}
		</style>
	</head>
	
	<body>
		<table>
			<tr>
				<th>英文名</th>
				<th>中文名</th>
			</tr>
			<tr>
				<td>HTML</td>
				<td>超文本标记语言</td>
			</tr>
			<tr>
				<td>CSS</td>
				<td>层叠样式表</td>
			</tr>
		</table>
	</body>
</html>

Please note that in the above example the table There are double borders. This is because the table and th/td elements have separate boundaries.

To display a single border of a table, use the border-collapse property. As follows:

1.5 border-collapse attribute

valuecollapseseparate
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			table {
				border-collapse: collapse;
			}
			table,th,td {
				border: 1px solid black;
			}
		</style>
	</head>
	
	<body>
		<table>
			<tr>
				<th>英文名</th>
				<th>中文名</th>
			</tr>
			<tr>
				<td>HTML</td>
				<td>超文本标记语言</td>
			</tr>
			<tr>
				<td>CSS</td>
				<td>层叠样式表</td>
			</tr>
		</table>
	</body>
</html>

1.6 border-spacing 属性

(1)作用:该属性指定分隔边框模型中单元格边界之间的距离。除非 border-collapse 被设置为 separate,否则将忽略这个属性。尽管这个属性只应用于表,不过它可以由表中的所有元素继承。

(2)可能的值:

Description
If possible, the borders will be merged into a single border. The border-spacing and empty-cells properties
default values ​​will be ignored. The borders will be separated. The border-spacing and empty-cells properties are not ignored

描述

length length

规定相邻单元的边框之间的距离。使用 px、cm 等单位。不允许使用负值。

如果定义一个length参数,那么定义的是水平和垂直间距。

如果定义两个length参数,那么第一个设置水平间距,而第二个设置垂直间距。

1.7 caption-side属性

(1)作用:设置表格标题的位置,该属性指定了表标题相对于表框的放置位置。表标题显示为好像它是表之前(或之后)的一个块级元素。

(2)可能的值:

描述

top

默认值。把表格标题定位在表格之上。

bottom

把表格标题定位在表格之下。

(3)浏览器的兼容性:除IE外的所有主流浏览器都支持 caption-side 属性。如果已规定 !DOCTYPE,那么 Internet Explorer 8 (以及更高版本)支持 caption-side属性。

1.8 empty-cells 属性

(1)作用:该属性定义了不包含任何内容的表单元格如何表示。如果显示,就会绘制出单元格的边框和背景。除非 border-collapse 设置为 separate,否则将忽略这个属性。

(2)可能的值:

描述

hide

不在空单元格周围绘制边框。

show

在空单元格周围绘制边框。默认。

(3)浏览器的兼容性:除IE外的所有浏览器都支持 empty-cells 属性。如果已规定 !DOCTYPE,那么 Internet Explorer 8 (以及更高版本)支持 empty-cells 属性。

1.9 table-layout属性

(1)作用:来显示表格单元格、行、列的算法规则,该属性指定了完成表布局时所用的布局算法。

(2)两种算法:

固定表格布局: fixed

#优点:允许浏览器更快地对表格进行布局, (在固定表格布局中,水平布局仅取决于表格宽度、列宽度、表格边框宽度、单元格间距,而与单元格的内容无关。通过使用固定表格布局,用户代理在接收到第一行后就可以显示表格。);

#缺点:不太灵活。

自动表格布局:automatic

#优点:更能反映传统的 HTML,(在自动表格布局中,列的宽度是由列单元格中没有折行的最宽的内容设定的。);

#缺点:自动算法比较慢,这是由于它需要在确定最终的布局之前访问表格中所有的内容。

(3)可能的值:

描述

automatic

默认。列宽度由单元格内容设定。

fixed

列宽由表格宽度和列宽度设定。

inherit

规定应该从父元素继承 table-layout 属性的值。


2.CSS表格的宽度和高度(width、height)

width和height属性定义表格的宽度和高度。

下面的例子是设置30%的宽度,30像素的th元素,20像素的td元素的高度的表格:

小实例: 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			table,th,td {
				border: 1px solid black;
			}
			table {
				width: 30%;
			}
			th {
				height: 30px;
			}
			td {
				height: 20px;
			}
		</style>
	</head>
	
	<body>
		<table>
			<tr>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td>张三</td>
				<td>男</td>
				<td>31</td>
			</tr>
			<tr>
				<td>李四</td>
				<td>男</td>
				<td>43</td>
			</tr>
			<tr>
				<td>王五</td>
				<td>男</td>
				<td>24</td>
			</tr>
		</table>
	</body>
</html>


3.CSS表格的文字对齐方式(text-align)

表格中的文本对齐和垂直对齐属性。

text-align属性设置水平对齐方式,向左,右,或中心。

vertical-align属性设置垂直对齐方式,比如顶部,底部或中间。

小实例: 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			table,th,td {
				border: 1px solid black;
			}
			th {
				width: 40%;
				height: 30px;
				text-align: center;
			}
			td {
				width: 40%;
				height: 20px;
				text-align: center;
			}
		</style>
	</head>
	
	<body>
		<table>
			<tr>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td>张三</td>
				<td>男</td>
				<td>31</td>
			</tr>
			<tr>
				<td>李四</td>
				<td>男</td>
				<td>43</td>
			</tr>
			<tr>
				<td>王五</td>
				<td>男</td>
				<td>24</td>
			</tr>
		</table>
	</body>
</html>


4.CSS表格填充(padding)

padding 简写属性在一个声明中设置所有填充属性。该属性可以有1到4个值。 

说明
length 规定以具体单位计的填充值,比如像素、厘米等。默认值是 0px
% 规定基于父元素的宽度的百分比的填充
inherit 指定应该从父元素继承padding

小实例: 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			table,th,td {
				border: 1px solid black;
			}
			th,td {
				padding: 15px;
			}
		</style>
	</head>
	
	<body>
		<table>
			<tr>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td>张三</td>
				<td>男</td>
				<td>31</td>
			</tr>
			<tr>
				<td>李四</td>
				<td>男</td>
				<td>43</td>
			</tr>
			<tr>
				<td>王五</td>
				<td>男</td>
				<td>24</td>
			</tr>
		</table>
	</body>
</html>


5.CSS表格的背景颜色及字体颜色(background-color、color)

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			table,th,td {
				border: 1px solid black;
			}
			th {
				background-color: burlywood;
				color: aqua;
			}
			td {
				background-color: chartreuse;
				color: brown;
			}
			caption {
				caption-side: bottom;
			}
		</style>
	</head>
	
	<body>
		<table>
			<caption>表1.1-学生个人信息表</caption>
			<tr>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td>张三</td>
				<td>男</td>
				<td>31</td>
			</tr>
			<tr>
				<td>李四</td>
				<td>男</td>
				<td>43</td>
			</tr>
			<tr>
				<td>王五</td>
				<td>男</td>
				<td>24</td>
			</tr>
		</table>
	</body>
</html>


6.CSS表格多属性综合练习

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>CSS简单学习</title>
		<style type="text/css">
			/*对应整个表格的样式*/
			#LOL {
				font-family: "楷体", sans-serif;
				width: 50%;
				height: 100%;
				text-align: center;
				border-collapse: collapse;
			}
			/*对应表格中的边框线的样式*/
			#LOL th,#LOL td {
				font-size: 20px;
				border: 1px solid #00FFFF;
				padding-top: 3px;
				padding-bottom: 3px;
				padding-left: 5px;
				padding-right: 10px;
			}
			/*对应表格表头的样式*/
			#LOL th {
				font-size: 30px;
				padding-top: 3px;
				padding-bottom: 3px;
				padding-left: 5px;
				padding-right: 10px;
				background-color: #7FFF00;
				color: deeppink;
			}
			/*对应表格中行为a的列的样式*/
			#LOL tr.a td {
				background-color: #DEB887;
				color: #FF0000;
			}
			/*对应表格中行为b的列的样式*/
			#LOL tr.b td {
				background-color: antiquewhite;
				color: #FF1493;
			}
			/*对应表格标题的样式*/
			caption {
				font-size: 16px;
				caption-side: bottom;
			}
		</style>
	</head>
	
	<body>
		<table id="LOL">
			<caption>表6.66-英雄联盟娱乐信息表</caption>
			<tr>
				<th>英雄名称</th>
				<th>定位</th>
				<th>推荐符文</th>
				<th>可选神话装备</th>
			</tr>
			<tr class="a">
				<td>熔岩巨兽</td>
				<td>辅助</td>
				<td>不灭之握</td>
				<td>霜火护手</td>
			</tr>
			<tr class="b">
				<td>战争女神</td>
				<td>AD Carry</td>
				<td>致命节奏</td>
				<td>海妖杀手</td>
			</tr>
			<tr class="a">
				<td>战争之影</td>
				<td>打野</td>
				<td>征服者</td>
				<td>三项之力</td>
			</tr>
			<tr class="b">
				<td>诺克萨斯之手</td>
				<td>上单</td>
				<td>征服者</td>
				<td>渴血战斧</td>
			</tr>
			<tr class="a">
				<td>疾风剑豪</td>
				<td>中单</td>
				<td>征服者</td>
				<td>不朽盾弓</td>
			</tr>
		</table>
	</body>
</html>

(学习视频分享:css视频教程

The above is the detailed content of What are the table attributes of css3. 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
HTML and React's Integration: A Practical GuideHTML and React's Integration: A Practical GuideApr 21, 2025 am 12:16 AM

HTML and React can be seamlessly integrated through JSX to build an efficient user interface. 1) Embed HTML elements using JSX, 2) Optimize rendering performance using virtual DOM, 3) Manage and render HTML structures through componentization. This integration method is not only intuitive, but also improves application performance.

React and HTML: Rendering Data and Handling EventsReact and HTML: Rendering Data and Handling EventsApr 20, 2025 am 12:21 AM

React efficiently renders data through state and props, and handles user events through the synthesis event system. 1) Use useState to manage state, such as the counter example. 2) Event processing is implemented by adding functions in JSX, such as button clicks. 3) The key attribute is required to render the list, such as the TodoList component. 4) For form processing, useState and e.preventDefault(), such as Form components.

The Backend Connection: How React Interacts with ServersThe Backend Connection: How React Interacts with ServersApr 20, 2025 am 12:19 AM

React interacts with the server through HTTP requests to obtain, send, update and delete data. 1) User operation triggers events, 2) Initiate HTTP requests, 3) Process server responses, 4) Update component status and re-render.

React: Focusing on the User Interface (Frontend)React: Focusing on the User Interface (Frontend)Apr 20, 2025 am 12:18 AM

React is a JavaScript library for building user interfaces that improves efficiency through component development and virtual DOM. 1. Components and JSX: Use JSX syntax to define components to enhance code intuitiveness and quality. 2. Virtual DOM and Rendering: Optimize rendering performance through virtual DOM and diff algorithms. 3. State management and Hooks: Hooks such as useState and useEffect simplify state management and side effects handling. 4. Example of usage: From basic forms to advanced global state management, use the ContextAPI. 5. Common errors and debugging: Avoid improper state management and component update problems, and use ReactDevTools to debug. 6. Performance optimization and optimality

React's Role: Frontend or Backend? Clarifying the DistinctionReact's Role: Frontend or Backend? Clarifying the DistinctionApr 20, 2025 am 12:15 AM

Reactisafrontendlibrary,focusedonbuildinguserinterfaces.ItmanagesUIstateandupdatesefficientlyusingavirtualDOM,andinteractswithbackendservicesviaAPIsfordatahandling,butdoesnotprocessorstoredataitself.

React in the HTML: Building Interactive User InterfacesReact in the HTML: Building Interactive User InterfacesApr 20, 2025 am 12:05 AM

React can be embedded in HTML to enhance or completely rewrite traditional HTML pages. 1) The basic steps to using React include adding a root div in HTML and rendering the React component via ReactDOM.render(). 2) More advanced applications include using useState to manage state and implement complex UI interactions such as counters and to-do lists. 3) Optimization and best practices include code segmentation, lazy loading and using React.memo and useMemo to improve performance. Through these methods, developers can leverage the power of React to build dynamic and responsive user interfaces.

React: The Foundation for Modern Frontend DevelopmentReact: The Foundation for Modern Frontend DevelopmentApr 19, 2025 am 12:23 AM

React is a JavaScript library for building modern front-end applications. 1. It uses componentized and virtual DOM to optimize performance. 2. Components use JSX to define, state and attributes to manage data. 3. Hooks simplify life cycle management. 4. Use ContextAPI to manage global status. 5. Common errors require debugging status updates and life cycles. 6. Optimization techniques include Memoization, code splitting and virtual scrolling.

The Future of React: Trends and Innovations in Web DevelopmentThe Future of React: Trends and Innovations in Web DevelopmentApr 19, 2025 am 12:22 AM

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment