I have a query which returns correct results form the database, I want to populate a HTML table with the results. However, I only get the data "raw" displayed, the table is not displayed like it should be according to the CSS class.
My question: Are my table class tags placed at the correct point? I think here is the error somewhere.
<table class="table-class">
<thead>
<tr><th>Car</th><th>Year</th><th>HP</th><th>Seats</th></tr>
</thead>
<tbody>
<?php
while($row = $resultsql->fetch_assoc()){
?>
<tr>
<td>
<?php echo $row['Car']; ?>
</td>
<td>
<?php echo $row['Year']; ?>
</td>
<td>
<?php echo $row['HP']; ?>
</td>
<td>
<?php echo $row['Seats']; ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
My CSS:
.table-class {
margin: 1em 0;
width: 100%;
}
@media (min-width: 480px) {
.table-class {
width: auto;
}
}
.table-class tr {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
}
.table-class tr td {
text-align: left;
}
@media (min-width: 480px) {
.table-class tr td {
text-align: center;
}
}
.table-class tr td:first-of-type {
text-align: left;
}
.table-class th {
display: none;
}
.table-class td {
display: block;
}
.table-class td:first-child {
padding-top: .5em;
}
.table-class td:last-child {
padding-bottom: .5em;
}
.table-class td:before {
content: attr(data-th) ": ";
font-weight: bold;
width: 9em;
display: inline-block;
}
@media (min-width: 480px) {
.table-class td:before {
display: none;
}
}
.table-class th:first-of-type {
text-align: left;
}
.table-class th, .table-class td {
text-align: center;
}
@media (min-width: 480px) {
.table-class th, .table-class td {
display: table-cell;
padding: .25em .5em;
}
.table-class th:first-child, .table-class td:first-child {
padding-left: 0;
}
.table-class th:last-child, .table-class td:last-child {
padding-right: 0;
}
}
.table-classshould be included.<tbody>…</tbody>tags? The<table class="table-class">is right, btw.}.<table class=...>try out<table style="color:blue;">and see if it's blue then.