表格标签table

表格 table:
     表格的行:tr
     每行中的列:td
     表格的标题:<th></th> 默认加粗,单元格居中
     表格头:caption
    [常用属性]
    1、border:给表格添加边框。
        当border属性增大时,只有外围框线增加,单元格的边框始终为1px
    2、bordercolor="blue"边框颜色
    3、Width、 Height:表格的宽高
    4、Cellspacing:单元格与单元格之间的间隙距离。
       当cellspacing="0",只会使单元格间隙为0,但不会合并边框线。
       表格边框合并:style="border-collapse: collapse;",
       无需再写cellspacing="0"
    5、Cellpadding:每个单元格中的内容与边框线的距离。
    6、align:表格在屏幕的左中右位置显示,left center right
       注意:给表格加上align属性,相当于让表格浮动。
       会直接打破表格后面元素的原有排列方式
    7、bgcolor:背景色   等同于style="background-color:;"
    8、background:   background="img/computer.jpg"设置背景图片
      等同于style="background-image:;" 且背景图会覆盖背景色

 

trtd相关的属性】
    1width/height: 单元格的宽高
    2bgcolor:单元格的背景颜色
    3align: left center right 单元格中的文字,水平对齐方式
    4valign:top center bottom 单元格中的文字,垂直对齐方式
    5nowrap="nowrap" 单元格中文字不换行

    注意:1、当表格属性与行列属性冲突时,以行列属性为准。(近者优先,就近原则)
         2、表格的align属性,是控制表格自身在浏览器的显示位置;
            行和列的align属性,是控制单元格中文字在单元格中的对齐方式;
         3、表格的align属性,并不影响表格内,文字的水平对齐方式
            tralign或者valign属性,可以控制一行中所有单元格的水平或者垂直对齐方式

 

 

 [表格的跨行与跨列]---td
         colspan 跨列,当某个格跨N列时,其右边N-1个单元格需删除
         rowspan 跨行,当某个格跨N行时,其下方N-1个单元格需删除
  
例:
<table border="1" align="center">
    <caption>我是表格标题!!!</caption>
    <tr>
        <td>第一行第一列</td>
        <td colspan="3">第一行第二列</td>
    </tr>
    <tr>
        <td rowspan="3">第二行跨三行</td>
        <td>第二行第二列</td>
        <td>第二行第三列</td>
        <td>第二行第四列</td>
    </tr>
    <tr>
        <td>第三行</td>
        <td>第三行</td>
        <td>第三行</td>
    </tr>
    <tr>
        <td>第四行</td>
        <td>第四行</td>
        <td>第四行</td>
    </tr>
</table>

 


 完整表格结构:caption thead  tbody  tfoot
 无论各部分在表格什么位置,显示时,        
         caption均在表格外最上方,
         thead均会在表格内最上方,
         tfoot均会在最下方。
         【表格的直列化】
         <colgroup style="background-color: yellow;">   前两列为一组
            <col />      第一列
            <col />      第二列
         </colgroup>
         <col style="background-color: blue;"/>         第三列

   【优点】
     1:语义化:看到标签能明白包含的内容
     2:便于浏览器搜索。
     3:可以调整书写顺序实现某些部分的优先展示,而不打乱显示顺序。
例:
<br>
<table width="500" align="center">
    <colgroup style="background-color: red"> <!--前两列为一组-->
       
<col/> <!--第一列-->
   
</colgroup>
    <colgroup style="background-color: yellow">
        <col/> <!--第二列-->
       
<col/> <!--第三列-->
   
</colgroup>

    <caption>表格标题</caption>

    <thead>
    <tr>
        <th>头1</th>
        <th>头2</th>
        <th>头3</th>
    </tr>
    </thead>

    <tbody>
    <tr>
        <td>111</td>
        <td>111</td>
        <td>111</td>
    </tr>
    <tr>
        <td>222</td>
        <td>222</td>
        <td>222</td>
    </tr>
    </tbody>

    <tbody>
    <tr>
        <td>111</td>
        <td>111</td>
        <td>111</td>
    </tr>
    <tr>
        <td>222</td>
        <td>222</td>
        <td>222</td>
    </tr>
    </tbody>

    <tfoot >
    <tr>
        <td>尾1</td>
        <td>尾2</td>
        <td>尾3</td>
    </tr>
    </tfoot>
</table>
原文地址:https://www.cnblogs.com/liuyuancheng/p/7252656.html