语法:
<element span="number">
示例1:在<col>元素中使用span属性
<col> 标签为表格中一个或多个列定义属性值。如需对全部列应用样式,<col> 标签很有用,这样就不需要对各个单元和各行重复应用样式了。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h2>HTML col span属性</h2> <table border="1"> <colgroup> <col span="2" style="background-color:pink"> <col style="background-color:plum"> </colgroup> <tr> <th>Name</th> <th>Branch</th> <th>Expenses</th> </tr> <tr> <td>BITTU</td> <td>CSE</td> <td>2500.00</td> </tr> <tr> <td>RAKESH</td> <td>ECE</td> <td>1400.00</td> </tr> </table> </body> </html>
效果图:
示例2:在<colgroup>元素中使用span属性
<colgroup> 标签用于对表格中的列进行组合,以便对其进行格式化。如需对全部列应用样式,<colgroup> 标签很有用,这样就不需要对各个单元和各行重复应用样式了。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> table { color: white; background: pink; } td { padding: 10px; } </style> </head> <body> <h2>HTML colgroup span属性</h2> <table> <colgroup span="2" style="background-color:green"></colgroup> <tr> <th>S.No</th> <th>Title</th> <th>id</th> </tr> <tr> <td>No.1</td> <td>hello world!</td> <th>id_1</th> </tr> <tr> <td>No.2</td> <td>hello world!</td> <th>id_2</th> </tr> </table> </body> </html>
效果图:
注:<colgroup> 标签只能在 table 元素中使用。
浏览器支持
● Google Chrome
● Internet Explorer
● Firefox
● Apple Safari
● Opera
以上就是HTML的span属性怎么用?的详细内容,更多请关注0133技术站其它相关文章!