0
I am creating the following responsive table, but it does not agree with what I want:
CSS:
table {
max-width: 100%;
background-color: transparent;
border-collapse: collapse;
border-spacing: 0;
font-family: arial;
}
.table {
border-bottom: #999999 solid 1px;
width: 100%;
margin-bottom: 20px;
}
.table th,
.table td {
border-right: #999999 solid 1px;
font-size: 8px;
padding: 8px;
line-height: 10px;
text-align: left;
vertical-align: middle;
}
.table td:last-child {
border-right: 0;
}
.table thead th {
font-weight: normal;
background-color: #005dab;
color: #fff;
font-size: 8px;
}
.table tbody > tr:nth-child(odd) > td,
.table tbody > tr:nth-child(odd) > th {
background-color: #f8f8f8;
}
/* Small Sizes */
@media (max-width: 767px) {
/* Responsive Table */
.table-responsive {
display: block;
position: relative;
width: 100%;
}
.table-responsive thead,
.table-responsive tbody,
.table-responsive th,
.table-responsive td,
.table-responsive tr {
display: block;
}
.table-responsive td,
.table-responsive th {
height: 35px;
}
.table-responsive thead {
float: left;
}
.table-responsive tbody {
width: auto;
position: relative;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
white-space: nowrap;
}
.table-responsive tbody tr {
display: inline-block;
}
.table td:last-child {
border-right: #999999 solid 1px;
}
}
Code:
$result_cursos = "SELECT * FROM raddb.ListagemPrduto WHERE Ativo = '1'";
$resultado_cursos = mysqli_query($conn, $result_cursos);
$tabela1 .= '<table class="table table-responsive">';
$tabela1 .= '<tr>';
$tabela1 .='<thead>';
$tabela1 .= '<tr>';
$tabela1 .= '<th rowspan=2>Produtos</th>';
$tabela1 .= '<th colspan=2>No Carro</th>';
$tabela1 .= '<th colspan=2>Na Prateleira</th>';
$tabela1 .= '<th colspan=2>Data na Emb.</th>';
$tabela1 .= '<th rowspan=2>Observação</th>';
$tabela1 .= '</tr>';
$tabela1 .= '<tr>';
$tabela1 .= '<th>Tem</th>';
$tabela1 .= '<th>Não Tem</th>';
$tabela1 .= '<th>Tem</th>';
$tabela1 .= '<th>Não Tem</th>';
$tabela1 .= '<th>Tem</th>';
$tabela1 .= '<th>Não Tem</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
$tabela1 .='<tbody>';
$y = 0;
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<div>';
$tabela1 .= '<tr>';
$tabela1 .= '<td> <input type="text" readonly="true" size="20" name= "Produto['.$y.']" class= "Produto" value="'.$rows_cursos['Descricao'].'"></td>';
$tabela1 .= '<td> <input type="radio" class="r" name= "Sim['.$y.']" value="Ok" required></td>';
$tabela1 .= '<td> <input type="radio" class="r" name= "Sim['.$y.']" value="Não Ok" required></td>';
$tabela1 .= '<td> <input type="radio" class="p" name= "Stock['.$y.']" value="Ok"></td>';
$tabela1 .= '<td> <input type="radio" class="p" name= "Stock['.$y.']" value="Não Ok"></td>';
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Ok" '.$property.'></td>';
$tabela1 .= '<td> <input type="radio" name= "DataP['.$y.']" value="Não Ok" '.$property.'></td>';
$tabela1 .= '<td> <textarea type="text" class= "Observacao" name="Observacao['.$y.']" rows="2" cols="30"></textarea></td>';
$tabela1 .= '</tr>';
$y++;
}
$tabela1 .='</tbody>';
$tabela1 .= '</table>';
$tabela1 .= '</div>';
$tabela1 .= '</div>';
echo $tabela1;
If visualized in computer screen, returns like this:
If it’s on the mobile screen it looks like this:
The headers are different, even vertically should be the same format as the horizontal header
HTML rendered:
<table class="table table-responsive" id="example">
<thead>
<tr>
<th>Quarto</th>
<th>Utente</th>
<th>Inicio Tarefa</th>
<th>Tarefa</th>
<th>Fim Tarefa</th>
<th>Colaborador</th>
<th>Observações</th>
</tr>
</thead>
<tbody>
<tr>
<?php
do{
?>
<td><?php echo $produto["Quarto"]; ?></td>
<td><?php echo $produto["nome"]; ?></td>
<td><?php echo $produto["IniciarTarefa"]; ?></td>
<td><?php echo $produto["Descricao"]; ?></td>
<td><?php echo $produto["FimTarefa"]; ?></td>
<td><?php echo $produto["Colaborador"]; ?></td>
<td><?php echo $produto["Observacao"]; ?></td>
</tr>
<?php } while($produto = $result1->fetch_assoc()); ?>
</tbody>
</table>
Face and pq you are messing with the table display. Pq you are changing it the other tr/td display? The table was supposed to work perfectly, which is "spoiling" and you changing the original display to another... If you can edit the question tb, and put a table that has already rendered side in HTML, with the HTML code itself
– hugocsl
@hugocsl already edited the question and added table with html code
– Bruno
Are you using Bootstrap? If yes which version?
– hugocsl