【CSS系列】对表单和数据表格应用样式

表格特有的元素:

1、summary和caption

caption用作与表格的标题。summary应用于表格标签,用来描述表格的内容,于image标签的alt文本相似。

2、thead tbody 和tfoot

这3个标签可以让开发人员将表格划分为逻辑部分。

行和列标题应该使用th标记而不是td,但是如果某些内容既是标题又是数据,那么仍然应该使用td,表格标题可以设置值为row或col的scope属性,定义他们是行标题还是列标题。他们还可以设置值rowgroup和colgroup,表示他们与多行或多列相关。

3、col和colgroup

虽然tr元素使开发人员能够对整行应用样式,但是很难对整列应用样式。colgroup能够对使用col元素定义的一个或多个列进行分组。

4、将标签和表单关联起来

1 <label>email <input name="email" type="text"/></label><!--方式1-->
2 
3 <label for="email">email</label>
4 <input name="email" id="email" type="text"/><!--方式2-->

5、fieldset元素将表单组合起来

<form>
  <fieldset>
    <legend>health information</legend>
    height: <input type="text" />
    weight: <input type="text" />
  </fieldset>
</form>

 1 fieldset{
 2     margin:1em 0;
 3     padding:1em;
 4     border:1px solid #ccc;
 5     background:#f8f8f8;}
 6 legend{
 7     font-weight:bold;}
 8 
 9 <form>
10 <fieldset>
11  <legend>Your Contact Details</legend>
12  <p>
13  <label for="author">Name:</label>
14  <input name="author" id="author" type="text"/>
15  </p>
16   <p>
17  <label for="email">Email:</label>
18  <input name="email" id="email" type="text"/>
19  </p>
20   <p>
21  <label for="url">Web Address:</label>
22  <input name="url" id="url" type="text"/>
23  </p>
24  </fieldset>
25 </form>

 

posted @ 2017-04-17 14:54  霓裳梦竹  阅读(664)  评论(0编辑  收藏  举报