CSS中Table(表格)样式是如何设置?(代码实例)

本章给大家介绍csstable(表格)样式是如何设置?(代码实例)。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

一、表格边框

border 指定CSS表格边框,使用border属性。

下面的例子指定了一个表格的Th和TD元素的黑色边框:

table, th, td{border: 1px solid black;}

请注意,在上面的例子中的表格有双边框。这是因为表和th/ td元素有独立的边界。

立即学习“前端免费学习笔记(深入)”;

为了显示一个表的单个边框,使用 border-collapse属性。

二、折叠边框

border-collapse 属性设置表格的边框是否被折叠成一个单一的边框或隔开:

table{border-collapse:collapse;}table,th, td{border: 1px solid black;}

三、表格宽度和高度

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

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

table {width:100%;}th{height:50px;}

四、表格文字对齐

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

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

td{text-align:right;}

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

td{height:50px;vertical-align:bottom;}

五、表格填充

padding 如果在表的内容中控制空格之间的边框,应使用td和th元素的填充属性:

td{padding:15px;}

六、表格颜色

下面的例子指定边框的颜色,和th元素的文本和背景颜色:

table, td, th { border:1px solid green; } th { background-color:green; color:white; }

 七、示例

 CSS教程#customers{    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;    width:100%;    border-collapse:collapse;}#customers td, #customers th {    font-size:1em;    border:1px solid #98bf21;    padding:3px 7px 2px 7px;}#customers th {    font-size:1.1em;    text-align:left;    padding-top:5px;    padding-bottom:4px;    background-color:#A7C942;    color:#ffffff;}#customers tr.alt td {    color:#000000;    background-color:#EAF2D3;}
Company Contact Country
Alfreds FutterkisteMaria AndersGermany
Berglunds snabbköpChristina BerglundSweden
Centro comercial MoctezumaFrancisco ChangMexico
Ernst HandelRoland MendelAustria
Island TradingHelen BennettUK
Königlich EssenPhilip CramerGermany
Laughing Bacchus WinecellarsYoshi TannamuriCanada
Magazzini Alimentari RiunitiGiovanni RovelliItaly
North/SouthSimon CrowtherUK
Paris spécialitésMarie BertrandFrance

效果图:

2.png

以上就是CSS中Table(表格)样式是如何设置?(代码实例)的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1611770.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
CSS什么是id 和 Class选择器?id 和 Class选择器的用法(实例)
上一篇 2025年12月24日 02:33:00
图文详解CSS中!important 的使用方法
下一篇 2025年12月24日 02:33:08

相关推荐

发表回复

登录后才能评论
关注微信