HTML表格基础详解
在现在 div 大行其道的时代,table 这个标签似乎很少被人提及,到处都是 div+css 布局的书以及博客文章,但其实 table 以及连带的其他表格标签依然在网页中占很重要的地位,特别是后台展示数据的时候表格运用是否熟练就显得很重要,一个清爽简约的表格能够把繁杂的数据表现得很有条理,虽然 div 布局也可以做到,但是总没有表格来得方便。平时也经常接触到表格,现在总结一下表格的一些属性和样式,以及学习构思一些表格的样式,以便以后不时之需。
一、标签
<table>
<thead>
<tr>
<th>title</th>
<th>title</th>
<th>title</th>
</tr>
</thead>
<tbody>
<tr>
<td>the</td>
<td>testinglongstring</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>-</td>
<td>Row</td>
</tr>
<tr>
<td>the</td>
<td>third</td>
<td>Row</td>
</tr>
</tbody>
</table>
CSS:
table{
width: 300px;
border:1px solid #000;
}
table td,table th{
border:1px solid #000;
}


table {
width: 300px;
border: 1px solid #000;
table-layout: fixed;
word-wrap:break-word;
}
table td,
table th {
border: 1px solid #000;
}
.odd{
width: 120px;
}

<table>
<colgroup>
<col class="odd"></col>
<col class="even"></col>
<col class="odd"></col>
</colgroup>
<thead>
<tr>
<th>title</th>
<th>title</th>
<th>title</th>
</tr>
</thead>
<tbody>
<tr>
<td>the</td>
<td>testinglongstring</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>-</td>
<td>Row</td>
</tr>
<tr>
<td>the</td>
<td>third</td>
<td>Row</td>
</tr>
</tbody>
</table>
table {
width: 300px;
border: 1px solid #000;
}
table td,
table th {
border: 1px solid #000;
}
.odd{
width: 120px;
}


<table>
<tr>
<td>Row</td>
<td>One</td>
</tr>
<tr>
<td>Row</td>
<td></td>
</tr>
</table>
table {
border-collapse: separate;
border-spacing: 5px 20px;
empty-cells: hide;
border:1px solid #000;
}
td{
border:1px solid #000;
}

<table>
<tr>
<td>Row</td>
<td>One</td>
</tr>
<tr>
<td>Row</td>
<td>Two</td>
</tr>
</table>
table {
width: 200px;
border-left: 1px solid #000;
border-top: 1px solid #000;
border-collapse: collapse;
}
td {
border-right: 1px solid #000;
border-bottom: 1px solid #000;
}
table {
width: 200px;
border-collapse: collapse;
}
td {
border: 1px solid #000;
}

//#table可以是table的id,也可以是tbody的id
var element = document.getElementById("table");
var row_col = element.rows;
window.onload = function() {
for (var i = 0; i < row_col.length; i++) {
var cell_col = row_col[i].cells;
for (var j = 0; j < cell_col.length; j++) {
cell_col[j].addEventListener('mouseover', function() {
cellIndex(this, true);
}, false);
cell_col[j].addEventListener('mouseout', function() {
cellIndex(this, false);
}, false);
}
}
}
function cellIndex(element, bool) {
for (var i = 0; i < row_col.length; i++) {
var cell_col = row_col[i].cells;
for (var j = 0; j < cell_col.length; j++) {
if (element == cell_col[j]) {
highLight(j, bool);
}
}
}
}
function highLight(index, bool) {
for (var i = 0; i < row_col.length; i++) {
var cell_col = row_col[i].cells;
if (bool) {
//列高亮,#eee为高亮颜色
cell_col[index].style.backgroundColor = "#eee";
} else {
//移除列高亮,#fff为原来颜色
cell_col[index].style.backgroundColor = "#fff";
}
}
}
$(document).ready(
function() {
$('table td').hover(
function() {
//获取鼠标所在的 td 在所在行中的 index
var td_index = $(this).parent().children('td').index($(this)[0]);
$("table tr:not(:has(th))").each(
function(i){
$(this).children("td").eq(td_index).addClass('high_light');
}
);
},
function() {
var td_index = $(this).parent().children('td').index($(this)[0]);
$("table tr:not(:has(th))").each(
function(i){
$(this).children("td").eq(td_index).removeClass('high_light');
}
);
}
);
}
);
<table>
<thead>
<tr>
<th>title</th>
<th>title</th>
<th>title</th>
</tr>
</thead>
<tbody>
<tr>
<td>the</td>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>-</td>
<td>Row</td>
</tr>
<tr>
<td>the</td>
<td>third</td>
<td>Row</td>
</tr>
</tbody>
</table>
table {
width: 300px;
line-height: 2em;
font-family: Arial;
border-collapse: collapse;
}
thead tr {
color: #ae1212;
border-bottom: 2px solid #980000;
}
tbody tr {
color: #bd3030;
font-size: 0.8em;
border-bottom: 1px solid #ffaeae;
}
th {
font-weight: normal;
text-align: left;
}
th,td {
padding: 0 10px;
}
table {
width: 300px;
line-height: 2em;
font-family: Arial;
text-align: center;
border-collapse: collapse;
border-top: 2px solid #980000;
border-bottom: 2px solid #980000;
}
thead tr {
color: #ae1212;
}
tbody tr {
color: #bd3030;
font-size: 0.8em;
}
th {
font-weight: normal;
}
th,td {
border-left: 1px solid #ffaeae;
border-right: 1px solid #ffaeae;
}

table {
width: 300px;
line-height: 2em;
font-family: Arial;
border-collapse: collapse;
}
thead tr {
color: #902d2d;
background-color: #e09999;
border-bottom: 1px solid #fff;
}
tbody tr {
color: #ac5959;
font-size: 0.8em;
border-bottom: 1px solid #fff;
background-color: #ffe7e7;
}
tbody tr:hover {
background-color: #ffd4d4;
}
th {
font-weight: normal;
text-align: left;
}
th,td {
padding: 0 10px;
}


table {
width: 300px;
line-height: 2em;
font-family: Arial;
border-collapse: collapse;
}
th,td {
padding: 0 10px;
}
th {
color: #a03f3f;
font-weight: normal;
text-align: left;
background-color: #f2caca;
border: 1px solid #fff;
}
td{
color: #c48080;
font-size: 0.8em;
background-color: #fff3f3;
border-top: 1px solid #ffdede;
border-left: 1px solid #ffdede;
}
tbody tr:hover th{
background-color: #ffdede;
border-right:1px solid #ffdede;
color:#9a4242;
}
tbody tr:hover td{
background-color: #ffdede;
border-left:1px solid #ffdede;
border-top: 1px solid #ffdede;
color:#9a4242;
}
<table>
<colgroup>
<col class="odd"></col>
<col class="even"></col>
<col class="odd"></col>
<col class="even"></col>
</colgroup>
<thead>
<tr>
<th>title</th>
<th class="even_th">title</th>
<th>title</th>
<th class="even_th">title</th>
</tr>
</thead>
<tbody>
<tr>
<td>the</td>
<td>the</td>
<td>the</td>
<td>the</td>
</tr>
<tr>
<td>first</td>
<td>-</td>
<td>third</td>
<td>fourth</td>
</tr>
<tr>
<td>Row</td>
<td>Row</td>
<td>Row</td>
<td>Row</td>
</tr>
</tbody>
</table>
table {
width: 300px;
line-height: 2em;
font-family: Arial;
border-collapse: collapse;
text-align: center;
}
th,td {
padding: 0 10px;
}
th {
color: #a03f3f;
font-weight: normal;
}
td{
color: #c48080;
font-size: 0.8em;
}
thead th{
background-color: #fbdcdc;
}
.odd{
background-color: #fff3f3;
}
.even{
border-left:1px solid #fff;
border-right:1px solid #fff;
background-color: #ffe9e9;
}
.even_th{
background-color: #eec4c4;
}

<table>
<tr>
<td>the</td>
<td>the</td>
<td>the</td>
<td>the</td>
</tr>
<tr>
<td>first</td>
<td>-</td>
<td>third</td>
<td>fourth</td>
</tr>
<tr>
<td>Row</td>
<td>Row</td>
<td>Row</td>
<td>Row</td>
</tr>
</table>
table {
width: 300px;
line-height: 2em;
font-family: Arial;
border-width: 1px;
border-style: solid;
border-color: #eec4c4 #eec4c4 #fff #fff;
text-shadow: 0 1px 0 #FFF;
border-collapse: separate;
border-spacing:;
background-color: #ffe9e9;
}
th {
color: #a03f3f;
font-weight: normal;
text-align: left;
}
td {
color: #c48080;
font-size: 0.8em;
}
th,td {
padding: 0 10px;
border-width: 1px;
border-style: solid;
border-color: #fff #fff #eec4c4 #eec4c4;
}

本文来源:JuFoFu
本文地址:http://www.cnblogs.com/JuFoFu/p/5140302.html
HTML表格基础详解的更多相关文章
- 深入浅出DOM基础——《DOM探索之基础详解篇》学习笔记
来源于:https://github.com/jawil/blog/issues/9 之前通过深入学习DOM的相关知识,看了慕课网DOM探索之基础详解篇这个视频(在最近看第三遍的时候,准备记录一点东西 ...
- Dom探索之基础详解
认识DOM DOM级别 注::DOM 0级标准实际并不存在,只是历史坐标系的一个参照点而已,具体的说,它指IE4.0和Netscape Navigator4.0最初支持的DHTML. 节点类型 注:1 ...
- Android中Canvas绘图基础详解(附源码下载) (转)
Android中Canvas绘图基础详解(附源码下载) 原文链接 http://blog.csdn.net/iispring/article/details/49770651 AndroidCa ...
- javaScript基础详解(1)
javaScript基础详解 首先讲javaScript的摆放位置:<script> 与 </script> 可以放在head和body之间,也可以body中或者head中 J ...
- Python学习一:序列基础详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7858473.html 邮箱:moyi@moyib ...
- Python学习二:词典基础详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7862377.html 邮箱:moyi@moyib ...
- 三剑客基础详解(grep、sed、awk)
目录 三剑客基础详解 三剑客之grep详解 1.通配符 2.基础正则 3.grep 讲解 4.拓展正则 5.POSIX字符类 三剑客之sed讲解 1.sed的执行流程 2.语法格式 三剑客之Awk 1 ...
- java继承基础详解
java继承基础详解 继承是一种由已存在的类型创建一个或多个子类的机制,即在现有类的基础上构建子类. 在java中使用关键字extends表示继承关系. 基本语法结构: 访问控制符 class 子类名 ...
- java封装基础详解
java封装基础详解 java的封装性即是信息隐藏,把对象的属性和行为结合成一个相同的独立单体,并尽可能地隐藏对象的内部细节. 封装的特性是对属性来讲的. 封装的目标就是要实现软件部件的"高 ...
随机推荐
- Python 3基础教程12-常见的错误
本文来介绍几种常见的错误,任何人在刚开始接触一个新的语言,即使照着代码抄写,也可能会犯错误,这里我们就介绍几种常见的错误,看看你是否遇到过. 1. NameError: name 'xxx' is n ...
- 性能测试之siege
一.siege介绍 Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数 ...
- HDU 3775 Chain Code pick定理
pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积. 思路:http://blog.csdn.net ...
- Python中的返回函数与闭包
返回函数,顾名思义,就是高阶函数可以把函数作为return值返回.与闭包的关系是:闭包需要以返回函数的形式实现. 一. 返回函数 比如我们有一个求和函数: >>> def calc_ ...
- 【bzoj1195】[HNOI2006]最短母串 AC自动机+状态压缩+BFS最短路
原文地址:http://www.cnblogs.com/GXZlegend/p/6825226.html 题目描述 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串 ...
- Hacking Tools
Hacking Tools 种各样的黑客工具浩如天上繁星,这也让许多刚刚入门安全技术圈的童鞋感到眼花缭乱,本文整理了常用的安全技术工具,希望能够给你带来帮助.以下大部分工具可以在 GitHub 或 S ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Location of ESXi 5.1 log files
Purpose This article provides the default location of log files on an ESXi 5.1 host. For other produ ...
- Angular(一)
一.Angular优点: 1.MVC:职责清晰,代码模块化. 2.模块化 3.指定系统——directive:我们已经在模板中看到了一些新的属性,这些属性不属于HTML规范.例如:我们引入了双花括号用 ...
- 51Nod 1558 树中的配对
题目链接 分析: 想了好久~~~还是得看题解...QwQ 首先因为是排列,所以我们猜想要把式子拆开来看, $ \sum dis(i,p[i])=\sum dep[i]+dep[p[i]]-2*dep[ ...