我的PHP代码对于填充了一些数据库内容的表有一点问题。我试图将每个注册与div中的表分开。我该怎么做才能摆脱第二和第三个注册div上可见的空间?
表示例:
<?php
$selected = $DBcon->query("SELECT * FROM lucrari, editors");
while($row = mysqli_fetch_array($selected)){
echo '<div class="lucrare">';
echo '<table class="tabel_lucrari">';
echo '<tr>';
echo '<th><div class="titlu_lucrare"><a href="lucrare.php?id_lucrare='.$row['id_lucrare'].'"'.'>'.$row['titlu'].'</a></div></th>';
echo '<th></th>';
echo '<tr>';
echo '<tr>';
echo '<td rowspan="3">'.'<img src="'.$row['avatar'].'">'.'</td>';
echo '<td><div class="text_lucrare">Autor: </div>'.$row['autor'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td><div class="text_lucrare">Disciplina: </div>'.$row['disciplina'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td>'.'<div class="text_lucrare">Data postarii: </div>'.$row['data'].'</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '<br>';
}
?>
答案 0 :(得分:1)
如果你谈论每张桌子之间的空间,请执行以下操作:
删除最后的echo '<br>';
。
如果你还有空间,请尝试以下方法: 添加CSS
.lucrare {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
}
更新:我看到你的问题扩展了表格标题,你可以随时使用这个css进行调试,然后在完成后将其删除:
table, th, td {
border: 1px solid black;
}
通过这样做,您可以轻松地看到问题。使用colspan="2"
,如果您有边框,则可能需要删除空的<th></th>
。
table, th, td {
border: 1px solid black;
}
&#13;
<div class="lucrare">
<table class="tabel_lucrari">
<tr>
<th>
<div class="titlu_lucrare"><a href="lucrare.php?id_lucrare='.$row['id_lucrare'].'" '.'>'.$row['titlu'].'</a></div>
</th>
<th></th>
<tr>
<tr>
<td rowspan="3">'.'<img src="'.$row['avatar'].'">'.'</td>
<td>
<div class="text_lucrare">Autor: </div>'.$row['autor'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Disciplina: </div>'.$row['disciplina'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Data postarii: </div>'.$row['data'].'</td>
</tr>
</table>
</div>
<br>
<div class="lucrare">
<table class="tabel_lucrari">
<tr>
<th>
<div class="titlu_lucrare"><a href="lucrare.php?id_lucrare='.$row['id_lucrare'].'" '.'>This Title is too long...Sorry!</a></div>
</th>
<th></th>
<tr>
<tr>
<td rowspan="3">'.'<img src="'.$row['avatar'].'">'.'</td>
<td>
<div class="text_lucrare">Autor: </div>'.$row['autor'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Disciplina: </div>'.$row['disciplina'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Data postarii: </div>'.$row['data'].'</td>
</tr>
</table>
</div>
<br>
<div class="lucrare">
<table class="tabel_lucrari">
<tr>
<th colspan="2">
<div class="titlu_lucrare"><a href="lucrare.php?id_lucrare='.$row['id_lucrare'].'" '.'>This title is long too but use colspan can fix</a></div>
</th>
<tr>
<tr>
<td rowspan="3">'.'<img src="'.$row['avatar'].'">'.'</td>
<td>
<div class="text_lucrare">Autor: </div>'.$row['autor'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Disciplina: </div>'.$row['disciplina'].'</td>
</tr>
<tr>
<td>
<div class="text_lucrare">Data postarii: </div>'.$row['data'].'</td>
</tr>
</table>
</div>
<br>
&#13;
答案 1 :(得分:0)
导致出现空格,因为th
标记的宽度大于td
所在的avatar
。因此它调整了整个列的大小。
如果您将colspan
添加到th
元素,则应该没问题。
<th colspan="2"><div class="titlu_lucrare">
<a href="lucrare.php?id_lucrare='.$row['id_lucrare'].'"'.'>'.$row['titlu'].'</a></div>
</th>