简体   繁体   中英

Table cell vertical-alignment difference between baseline and top

I played around with different values of vertical-alignment in table-cells and found out the vertical-align:top and vertical-align:baseline behaves the same. Here is an example.

<!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">$100</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">$150</td>
  </tr>
</table>

</body>

http://jsfiddle.net/d6vron9k/ Is there any case where vertical-align:baseline differs from vertical-align:top ? If so could someone post an example illustrating that?

Is there any case where vertical-align:baseline differs from vertical-align:top ? If so could someone post an example illustrating that?

Sure.

 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">$100</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">$150</td> </tr> <tr> <td>Joe</td> <td>Swanson</td> <td>$300</td> </tr> <tr> <td>Cleveland</td> <td>Brown</td> <td>$250</td> </tr> </table> </body>

Or see http://jsfiddle.net/d6vron9k/2 .

I just added

td:first-child:first-letter {
    font-size: 3em;
}

(and changed the ids for classes, as they weren't unique.)

You can see that the text in the latter columns is lower in its cell for vertical-align: baseline than it is for vertical-align: top .

used to vertical-align: bottom;

as like this

td#baseline {
    vertical-align: bottom;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM