HTML系列(八):表格

来源:http://www.cnblogs.com/csxiaoyu/archive/2016/03/06/5248397.html
-Advertisement-
Play Games

一、基本表格: 表格標記<table>,行標記<tr>,單元格標記<td> 基本語法: <table> <tr> <td>單元格內文字</td> <td>單元格內文字</td> ...... </tr> <tr> <td>單元格內文字</td> <td>單元格內文字</td> ...... </tr


一、基本表格:

     表格標記<table>,行標記<tr>,單元格標記<td>

     基本語法:

<table>
    <tr>
        <td>單元格內文字</td>
        <td>單元格內文字</td>
        ......
    </tr>
        <tr>
        <td>單元格內文字</td>
        <td>單元格內文字</td>
        ......
    </tr>
        ......
</table>

     示例代碼:

  1 <!DOCTYPE html>  
  2 <html>  
  3 <head>  
  4 <meta charset="UTF-8"/>  
  5 <title>第9章</title>  
  6 </head>
  7 <style type="text/css">
  8 body {
  9   font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 10   color: #4f6b72;
 11   background: #E6EAE9;
 12 }
 13 
 14 a {
 15   color: #c75f3e;
 16 }
 17 
 18 #mytable {
 19   width: 700px;
 20   padding: 0;
 21   margin: 0;
 22 }
 23 
 24 caption {
 25   padding: 0 0 5px 0;
 26   width: 700px;
 27   font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 28   text-align: right;
 29 }
 30 
 31 th {
 32   font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 33   color: #4f6b72;
 34   border-right: 1px solid #C1DAD7;
 35   border-bottom: 1px solid #C1DAD7;
 36   border-top: 1px solid #C1DAD7;
 37   letter-spacing: 2px;
 38   text-transform: uppercase;
 39   text-align: left;
 40   padding: 6px 6px 6px 12px;
 41   background: #CAE8EA url(images/bg_header.jpg) no-repeat;
 42 }
 43 
 44 th.nobg {
 45   border-top: 0;
 46   border-left: 0;
 47   border-right: 1px solid #C1DAD7;
 48   background: none;
 49 }
 50 
 51 td {
 52   border-right: 1px solid #C1DAD7;
 53   border-bottom: 1px solid #C1DAD7;
 54   background: #fff;
 55   font-size: 11px;
 56   padding: 6px 6px 6px 12px;
 57   color: #4f6b72;
 58 }
 59 
 60 td.alt {
 61   background: #F5FAFA;
 62   color: #797268;
 63 }
 64 
 65 th.spec {
 66   border-left: 1px solid #C1DAD7;
 67   border-top: 0;
 68   background: #fff url(images/bullet1.gif) no-repeat;
 69   font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 70 }
 71 
 72 th.specalt {
 73   border-left: 1px solid #C1DAD7;
 74   border-top: 0;
 75   background: #f5fafa url(images/bullet2.gif) no-repeat;
 76   font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 77   color: #797268;
 78 }
 79 </style>  
 80 <body>  
 81 <table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">  
 82 <caption>The technical specifications of the Apple PowerMac G5 series</caption>  
 83   <tr>  
 84     <th scope="col" abbr="Configurations">設置</th>  
 85     <th scope="col" abbr="Dual 1.8">1.8GHz</th>  
 86     <th scope="col" abbr="Dual 2">2GHz</th>  
 87  <th scope="col" abbr="Dual 2.5">2.5GHz</th>  
 88   </tr>  
 89   <tr>  
 90     <th scope="row" abbr="Model" class="spec">lipeng</th>  
 91     <td>M9454LL/A</td>  
 92     <td>M9455LL/A</td>  
 93     <td>M9457LL/A</td>  
 94   </tr>  
 95   <tr>  
 96     <th scope="row" abbr="G5 Processor" class="specalt">mapabc</th>  
 97     <td class="alt">Dual 1.8GHz PowerPC G5</td>  
 98     <td class="alt">Dual 2GHz PowerPC G5</td>  
 99     <td class="alt">Dual 2.5GHz PowerPC G5</td>  
100   </tr>  
101   <tr>  
102     <th scope="row" abbr="Frontside bus" class="spec">Lennvo</th>  
103     <td>900MHz per processor</td>  
104     <td>1GHz per processor</td>  
105     <td>1.25GHz per processor</td>  
106   </tr>  
107   <tr>  
108     <th scope="row" abbr="L2 Cache" class="specalt">Black</th>  
109     <td class="alt">512K per processor</td>  
110     <td class="alt">512K per processor</td>  
111     <td class="alt">512K per processor</td>  
112   </tr>  
113 </table>  
114 </body>  
115 </html>   
View Code

 

二、讓表格沒有凹凸感

     沒有樣式的情況下,表格邊框是凹凸的,可以使用cellspacing和cellpadding來取消凹凸感。cellspacing是td與td之間的距離,而cellpadding是單元格內部內容與單元格邊界之間的空白距離的大小。

     例如:

 1 <table border="1" cellpadding="0" cellspacing="0">
 2     <tr>
 3         <th>單元格內的標題</th>
 4         <th>單元格內的標題</th>    
 5     </tr>    
 6     <tr>
 7         <td>單元格內的文字</td>
 8         <td>單元格內的文字</td>
 9     </tr>
10     <tr>
11         <td>單元格內的文字</td>
12         <td>單元格內的文字</td>
13     </tr>
14 </table>

 

三、添加表頭th

 1 <!DOCTYPE html>
 2 <html lang="zh-CN">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
 6     <meta content="yes" name="apple-mobile-web-app-capable" />
 7     <meta content="black" name="apple-mobile-web-app-status-bar-style" />
 8     <meta name="format-detection" content="telephone=no" />
 9     <title>第9章</title>
10     </head>
11 <body>
12 <table cellspacing="0">
13     <tr>
14         <th>序號</th>
15         <th>歌曲名</th>
16         <th>演唱</th>
17     </tr>
18     <tr>
19         <th>01</th>
20         <td>小蘋果</td>
21         <td>筷子兄弟</td>
22     </tr>
23     <tr>
24         <th>02</th>
25         <td>匆匆那年</td>
26         <td>王菲</td>
27     </tr>
28     <tr>
29         <th>03</th>
30         <td>喜歡你</td>
31         <td>G.E.M.鄧紫棋</td>
32     </tr>
33     <tr>
34         <th>04</th>
35         <td>當你老了</td>
36         <td>莫文蔚</td>
37     </tr>
38 </table>
39 <body>
40 </body>
41 </html>
View Code

     為了更進一步區分表頭與內容,對錶格進行樣式設計,順便添加<thead>,<tbody>,<tfoot>標簽為表格完善結構,更進一步區別不同部分:

 1 <!DOCTYPE html>
 2 <html lang="zh-CN">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
 6     <meta content="yes" name="apple-mobile-web-app-capable" />
 7     <meta content="black" name="apple-mobile-web-app-status-bar-style" />
 8     <meta name="format-detection" content="telephone=no" />
 9     <title>第9章</title>
10 <style type="text/css">
11 th {
12 font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
13 color: #4f6b72;
14 border-right: 1px solid #C1DAD7;
15 border-bottom: 1px solid #C1DAD7;
16 border-top: 1px solid #C1DAD7;
17 letter-spacing: 2px;
18 text-transform: uppercase;
19 text-align: left;
20 padding: 6px 6px 6px 12px;
21 background: #CAE8EA url(images/bg_header.jpg) no-repeat;
22 }
23 
24 td {
25 border-right: 1px solid #C1DAD7;
26 border-bottom: 1px solid #C1DAD7;
27 background: #fff;
28 font-size: 11px;
29 padding: 6px 6px 6px 12px;
30 color: #4f6b72;
31 }
32 thead th {
33     color: red;
34 }
35 tfoot th {
36     color: blue;
37 }
38 </style>
39     </head>
40 <body>
41 <table cellspacing="0">
42     <thead>
43         <tr>
44             <th>序號</th>
45             <th>歌曲名</th>
46             <th>演唱</th>
47         </tr>
48     </thead>
49     <tbody>
50         <tr>
51             <th>01</th>
52             <td>小蘋果</td>
53             <td>筷子兄弟</td>
54         </tr>
55         <tr>
56             <th>02</th>
57             <td>匆匆那年</td>
58             <td>王菲</td>
59         </tr>
60         <tr>
61             <th>03</th>
62             <td>喜歡你</td>
63             	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • $(function(){ $("li").not(":even").css("color","red"); $("li").filter(":odd").css("color","red"); }) $(function(){ $("li").filter(function(index) { re
  • 本人沒有美工功底,學習html5的主要目的也不是為了做網頁設計, 而是學習其腳本語言javascript的編寫, 還有就是CSS. 於是在網上到處找html5開發的資料,html5的開發工具等等。 網上很多朋友都推薦有好幾款開發工具,我也試著下載安裝過有好幾款, 其中網友比較多使用的是dreamwe
  • 選擇器(selector)是CSS中很重要的概念,所有HTML語言中的標記都是通過不同的CSS選擇器進行控制的。用戶只需要通過選擇器對不同的HTML標簽進行控制,並賦予各種樣式聲明,即可實現各種效果。 1. * * { margin: 0; padding: 0; } 星號選擇器用於選取頁面中的所有
  • 近日在群里看到有個題目,拿出來寫寫, 要求: 用html,css,原生js實現如圖的效果,先正向輸出,然後逆向回溯,最後停留在完整的畫面。 首先: HTML部分代碼: <div id="result"></div> 就是這麼簡單一行搞定。 CSS代碼: #result{ width:550px; m
  • [1]定義 [2]方法 [3]相容
  • 1.原型鏈繼承:構造函數、原型和實例的關係:每個構造函數都有一個原型對象,原型對象都包含一個指向構造函數的指針,而實例都包含一個指向原型對象的內部指針。確認原型和實例之間的關係用instanceof。 原型鏈繼承缺點:字面量重寫原型會中斷關係,使用引用類型的原型,並且子類型還無法給超類型傳遞參數 f
  • [1]定義 [2]觸發條件 [3]作用
  • 一、表單標簽form 表單標簽用於申明表單,定義採集數據的範圍,即<form>包含的數據將被提交到資料庫上,包含了處理表單數據所用CGI程式的URL以及數據提交到伺服器的方法。 表單能夠包含 input 元素,比如文本欄位、覆選框、單選框、提交按鈕等等。還可以包含 menus、textarea、fi
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...