Table 基线和顶部之间的单元格垂直对齐差异
Table cell vertical-alignment difference between baseline and top
我在 table 单元格中尝试了不同的垂直对齐值,发现 vertical-align:top 和 vertical-align:baseline 的行为相同。
这是一个例子。
<!DOCTYPE html>
<style>
table, td, th {
border: 1px solid black;
}
td#top {
height: 50px;
vertical-align: top;
}
td#baseline {
height: 50px;
vertical-align: baseline;
}
</style>
<body>
<table>
<tr>
<td id="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td id="top">Griffin</td>
<td id="top">0</td>
</tr>
<tr>
<td id="baseline">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td id="baseline">Griffin</td>
<td id="baseline">0</td>
</tr>
</table>
</body>
http://jsfiddle.net/d6vron9k/
是否存在 vertical-align:baseline 与 vertical-align:top 不同的情况?
如果可以,有人可以 post 举例说明吗?
习惯于vertical-align: bottom;
像这样
td#baseline {
vertical-align: bottom;
}
希望它能消除困惑
Is there any case where vertical-align:baseline differs from
vertical-align:top ? If so could someone post an example illustrating
that?
当然可以。
table, td, th {
border: 1px solid black;
}
td.top {
height: 50px;
vertical-align: top;
}
td.baseline {
height: 50px;
vertical-align: baseline;
}
td:first-child:first-letter {
font-size: 3em;
}
<!DOCTYPE html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td class="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td class="top">Griffin</td>
<td class="top">0</td>
</tr>
<tr>
<td class="baseline">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td class="baseline">Griffin</td>
<td class="baseline">0</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>0</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>0</td>
</tr>
</table>
</body>
或参见http://jsfiddle.net/d6vron9k/2。
我刚刚添加
td:first-child:first-letter {
font-size: 3em;
}
(并更改了 类 的 ID,因为它们不是唯一的。)
您可以看到,vertical-align: baseline
后几列中的文本在单元格中的位置低于 vertical-align: top
。
我在 table 单元格中尝试了不同的垂直对齐值,发现 vertical-align:top 和 vertical-align:baseline 的行为相同。 这是一个例子。
<!DOCTYPE html>
<style>
table, td, th {
border: 1px solid black;
}
td#top {
height: 50px;
vertical-align: top;
}
td#baseline {
height: 50px;
vertical-align: baseline;
}
</style>
<body>
<table>
<tr>
<td id="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td id="top">Griffin</td>
<td id="top">0</td>
</tr>
<tr>
<td id="baseline">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td id="baseline">Griffin</td>
<td id="baseline">0</td>
</tr>
</table>
</body>
http://jsfiddle.net/d6vron9k/ 是否存在 vertical-align:baseline 与 vertical-align:top 不同的情况? 如果可以,有人可以 post 举例说明吗?
习惯于vertical-align: bottom;
像这样
td#baseline {
vertical-align: bottom;
}
希望它能消除困惑
Is there any case where vertical-align:baseline differs from vertical-align:top ? If so could someone post an example illustrating that?
当然可以。
table, td, th {
border: 1px solid black;
}
td.top {
height: 50px;
vertical-align: top;
}
td.baseline {
height: 50px;
vertical-align: baseline;
}
td:first-child:first-letter {
font-size: 3em;
}
<!DOCTYPE html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td class="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td class="top">Griffin</td>
<td class="top">0</td>
</tr>
<tr>
<td class="baseline">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</td>
<td class="baseline">Griffin</td>
<td class="baseline">0</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>0</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>0</td>
</tr>
</table>
</body>
或参见http://jsfiddle.net/d6vron9k/2。
我刚刚添加
td:first-child:first-letter {
font-size: 3em;
}
(并更改了 类 的 ID,因为它们不是唯一的。)
您可以看到,vertical-align: baseline
后几列中的文本在单元格中的位置低于 vertical-align: top
。