实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>4.CSS表格设置</title> <style> /*第一步:给整个表格以及内部的所有单元格加上边框*/ table,th,td { border: 1px solid #333; } /*第二步:将整个表格以及内部单元格的边框全部折叠,就是线条二合一*/ table { /*折叠表格线*/ border-collapse: collapse; text-align: center; width: 60%; /*表格居中*/ margin: 50px auto; box-shadow: 3px 3px 3px #888; background-image: url(./images/gs/bg.jpg); background-repeat: no-repeat; background-size: cover; } table caption { font-size: 1.6em; font-weight: bolder; margin-bottom: 30px; } th,td { padding: 10px; } td img { border-radius: 50%; box-shadow: 2px 2px 2px #888; } th { background-color: rgba(155,155,0,0.3); color: brown; } .green { color: darkgreen; font-weight: bolder; font-size: 1.2em; } #item1 { color: red; } </style> </head> <body> <table> <caption>爸爸去哪儿5嘉宾阵容</caption> <tr> <th>序号</th> <th>姓名</th> <th>身高(cm)</th> <th>头像</th> <th>职业</th> <th>特长</th> <th>兴趣</th> </tr> <tr> <td>1</td> <td id="item1">吴尊</td> <td>180</td> <td><img src="./images/gs/7.jpg" alt="" width="50" ></td> <td class="red">歌手</td> <td>打篮球</td> <td class="green">唱歌</td> </tr> <tr> <td >2</td> <td id="item1">杜江</td> <td>180</td> <td><img src="./images/gs/8.jpg" alt="" width="50"></td> <td class="red">演员</td> <td>游泳</td> <td class="green">看电影</td> </tr> <tr> <td >3</td> <td id="item1">陈小春</td> <td>170</td> <td><img src="./images/gs/6.jpg" alt="" width="50"></td> <td class="red">演员</td> <td>旅游</td> <td class="green">逛街</td> </tr> <tr> <td >4</td> <td id="item1">邓伦</td> <td>175</td> <td><img src="./images/gs/9.jpg" alt="" width="50"></td> <td class="red">演员</td> <td>踢足球</td> <td class="green">跑步</td> </tr> </table> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
案例实现截图:
手抄代码: