Table and CSS

This example shows draws a formatted table.

by Karel Jed Darang

HTML

<div class="labels">
    <p>First</p>
    <p>Last</p>
    <p>
    Position
    </p>
</div>



<p class="tablend" />

<table>
    <tr>
        <th>First</th>
        <th>Last</th>
        <th>Position</th>
    </tr>
    <tr>
        <td>Jane</td>
        <td>Doe</td>
        <td>Professor</td>
    </tr>
    <tr>
         <td>John</td>
        <td>Smith</td>
        <td>Senior Lecturer</td>
    </tr>
</table>

CSS

.labels>p {
  vertical-align:middle;
  float: left;
  margin: 2px 0px 0px 2px;
}



.tablend {
  clear: both;
  display:block;
  margin-bottom:10px;
}
.labels>p, th {
    font-weight: bold;
    background-color: darkblue;
    color: white;
}

.labels{
  width: 372px;
  margin: 0;
  padding: 0;
}

td {
    background-color: lightgray;
    color: black;
}

th, td {
    border-width: 1px;   /* contributes 2 to width and height   */
    padding: 10px;       /* contributes 20 to width and height  */
    font-size: 16px;     /* contributes 16px to veritcal height */
    width: 100px;
    text-align: center;
    border: 1px solid black;
}