首先說明:<th>列(字體會加粗),<td>列丸卷,<tr>行
1.普通表格
<style>
table, th, td {
border: 1px solid black;
}
</style>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
2.合并邊框
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
</style>
3.合并里面線
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
</style>
4.Table Width and Height
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
th {
height: 50px;
}
</style>
5.水平對齊
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
th {
text-align: left;
}
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
td {
height: 50px;
vertical-align: bottom;
}
</style>
6.Table Padding
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 15px;
}
</style>
7.水平分規(guī)
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
</style>
8.鼠標經(jīng)過有東西的表格
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover{background-color:#f5f5f5}
</style>
9.有條紋的表格
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
</style>
- 加上背景色
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
10.響應(yīng)時表格
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {[圖片上傳中...(拉動.JPG-cc9f7-1533173680116-0)]
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
</style>