使用CSS能够制作出十分精美的表格。

代码整理自w3school:http://www.w3school.com.cn

效果图:

代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" /> <title>CSS 表格样式</title> <head>
<style type="text/css">
body {background-color:#e8e8e8}
/*text-align 属性设置水平对齐方式,vertical-align 属性设置垂直对齐方式*/
table,th,td {border:1px solid blue;text-align:center}
table.singlineBorder {border-collapse:collapse;} /*单线条边框的表格*/
table.widthPercent30 {width:30%}
th.height50px {height:50px}
td.greenBg {color:#00aa00;background-color:#ccc} /*一个精美的表格*/
table.niceTable
{
width:30%;
border-collapse:collapse;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
}
table.niceTable td,table.niceTable th
{
padding:3px 7px 2px 7px;
border:1px solid #98bf21;
}
table.niceTable th
{
color:white;
background-color:#A7C942;
}
table.niceTable tr.light td {background-color:#EAF2D3;} </style>
</head> <body>
<h3>(一)蓝色边框的表格</h3>
<table cellpadding="10px">
<tr>
<th>省份</th>
<th>面积</th>
</tr>
<tr>
<td>黑龙江</td>
<td>47.2</td>
</tr>
<tr>
<td>辽宁</td>
<td>11.6</td>
</tr>
</table> <h3>(二)单线条边框的表格</h3>
<table cellpadding="10px" class="singlineBorder">
<tr>
<th>省份</th>
<th>面积</th>
</tr>
<tr>
<td>黑龙江</td>
<td>47.2</td>
</tr>
<tr>
<td>辽宁</td>
<td>11.6</td>
</tr>
</table> <h3>(三)表格宽度30%。高度50px,设置字体颜色和背景颜色</h3>
<table class="widthPercent30">
<tr>
<th class="height50px">省份</th>
<th class="height50px">面积</th>
</tr>
<tr>
<td>黑龙江</td>
<td class="greenBg">47.2</td>
</tr>
<tr>
<td>辽宁</td>
<td class="greenBg">11.6</td>
</tr>
</table> <h3>(四)一个美丽的表格</h3>
<table cellpadding="10px" class="niceTable">
<caption>省份基本信息</caption>
<tr>
<th>省份</th>
<th>省会</th>
<th>面积</th>
<th>人口</th>
<th>GDP</th>
</tr>
<tr>
<td>黑龙江</td>
<td>哈尔滨</td>
<td>47.2</td>
<td>4900</td>
<td>16000</td>
</tr>
<tr class="light">
<td>吉林</td>
<td>长春</td>
<td>11.6</td>
<td>2600</td>
<td>27000</td>
</tr>
<tr>
<td>辽宁</td>
<td>沈阳</td>
<td>12.6</td>
<td>4500</td>
<td>27000</td>
</tr>
<tr class="light">
<td>河北</td>
<td>石家庄</td>
<td>29.1</td>
<td>5200</td>
<td>26000</td>
</tr>
</table> </body> </html>

CSS:表格样式(设置表格边框/文字/背景的样式)的更多相关文章

  1. css3-5 css3鼠标、列表和尺寸样式怎么用(文字有关的样式会被继承)

    css3-5  css3鼠标.列表和尺寸样式怎么用(文字有关的样式会被继承) 一.总结 一句话总结:css标签中文字有关的样式会被继承.由常用样式记起. 1.鼠标常用样式有哪些? cursor:poi ...

  2. 各种CSS样式设置细线边框

    基础知识回顾 : cellspacing:单元格与单元格之间的边距:cellpadding:单元格内的内容与单元格边沿的边距 简单实用的样式,设置所有的单元格为细线效果 <style type= ...

  3. td 内容自动换行 table表格td设置宽度后文字太多自动换行

    设置table 的 style="table-layout:fixed;" 然后设置td的 style="word-wrap:break-word;" 即可   ...

  4. CSS属性定义 文本修饰 边框效果 背景修饰

    一.CSS属性定义1.css颜色表示方法[重点]rgb(红绿蓝3个颜色通道 强度值为0-255)rgb(0,0,0)rgba(alpha a是透明度 值为0-1)rgba(123,123,123,0) ...

  5. 通过CSS给图像设置圆角边框

    <html> <style> .smaller-image{ border-radius: 50%; width: 100px; } </style> <bo ...

  6. 第 17 章 CSS 边框与背景[下]

    学习要点: 1.设置背景 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 一.设置背景 盒模型的尺寸可以通过两种方式实现可见性, ...

  7. 第 17 章 CSS 边框与背景[上]

    学习要点: 1.声明边框 2.边框样式 3.圆角边框 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 一.声明边框 边框的声明有 ...

  8. 第七十四节,css边框与背景

    css边框与背景 学习要点: 1.声明边框 2.边框样式 3.圆角边框  本章主要探讨HTML5中CSS边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 声明边框 边框的声明有三个属性设 ...

  9. 使用 jQuery 基本选择器获取页面元素,然后利用 jQuery 对象的 css() 方法动态设置 <span> 和 <a> 标签的样式

    查看本章节 查看作业目录 需求说明: 使用 jQuery 基本选择器获取页面元素,然后利用 jQuery 对象的 css() 方法动态设置 <span> 和 <a> 标签的样式 ...

随机推荐

  1. hdu4177:Super Mario

    主席树+离散化.给一段区间.多次询问[l,r]中有多少个数小于k.啊主席树用指针版写出来优美多了QAQ... #include<cstdio> #include<cstring> ...

  2. 【转】NDK上建立自己的项目

    原文网址:http://www.cnblogs.com/sardine/archive/2011/07/30/2121845.html 建立Android.mk文件 ~/android-ndk/app ...

  3. Google Gson解析Json数据应用实例

    转自:http://lixigao449778967.blog.163.com/blog/static/24985164201269105928783/ 1.需要的Jar包 1) Google Gso ...

  4. dll打包进需要发布的exe z

    http://www.cnblogs.com/Jarvin/p/3721195.html 我们需要发布的exe文件很多时候都可能会依赖于一堆松散的dll,如果想在发布 的时候只提供exe文件,而不想把 ...

  5. Selenium2Library系列 keywords 之 _SelectElementKeywords 之_get_select_list_options(self, select_list_or_locator)

    def _get_select_list_options(self, select_list_or_locator): if isinstance(select_list_or_locator, Se ...

  6. SVN server 安装 并创建用户访问

    1. 下载svn   官网https://www.visualsvn.com/server/download/ 或者其他网站都行,下载是VisualSVN-Server-3.5.6.msi. 2.安装 ...

  7. 依赖注入框架Autofac源码阅读指南

    官方网站http://autofac.org/ 源码下载地址https://github.com/autofac/Autofac 最新版本是3.5.0 下载后大小为37M,包括源码,示例文档,与之相关 ...

  8. 面向对象基础3(class0523)

    怎么实现多态2-接口 接口是定义一种能力,规定子类能干什么和抽象类有些相似,解决类的单根继承.接口可以实现多继承 案例 鸟-麻雀sparrow,鸵鸟ostrich,企鹅penguin,鹦鹉parrot ...

  9. CUDA网格限制

    如图

  10. leetcode@ [315/215] Count of Smaller Numbers After Self / Kth Largest Element in an Array (BST)

    https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nu ...