我有一个div,它没有被里面的内容推倒。相反,内容只是与div 重叠。我认为这是因为div 标签之间有一个 PHP while 循环?我该如何解决这个问题?
session_start();
if (!$_SESSION["user_name"])
{
header("Location: index.php");
}
include('header.php');
$id = $_GET['id'];
if(isset($id)) {
connect_to_db();
mysql_query("DELETE FROM content WHERE id='$id'");
$deleted = 'Content Successfully Deleted.<br>';
}
echo '<div id="content">';
echo '<h2>Delete Content</h2>';
if(isset($deleted)){
echo $deleted;
}
connect_to_db();
$query="SELECT id, date, title, image FROM content ORDER BY date DESC";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){
echo '<div id="delete" align="center">';
echo '<a href="delete.php?id='.$row['id'].'"><img src="'.$row['image'].'" style="border:1px solid black; width:100px;"><br>Delete</a>';
echo '</div>';
}
echo '</div>';
将overflow: hidden;
CSS 规则放在包含重叠内容的div 上。
尝试清除while循环中的div,也许类似
while($row = mysql_fetch_array($result)){
echo '<div id="delete" align="center">';
echo '<a href="delete.php?id='.$row['id'].'"><img src="'.$row['image'].'" style="border:1px solid black; width:100px;"><br>Delete</a>';
echo '<div style="clear:both"></div></div>';
}
可能有帮助吗?或者将<a>
元素声明为块元素?
使用 PHP 循环与此问题无关,重要的是提供给您的 Web 浏览器的 HTML 代码。
尝试将clear: both;
样式添加到有问题的div:
<div id="delete" align="center" style="clear: both;">
您也可以使用 CSS 而不是 HTML 属性进行对齐:
<div id="delete" style="text-align: center; clear: both;">
更新我看到你的 DIV 元素正在跳跃,而不是像我最初想象的那样彼此相邻漂浮。
检查您的 CSS,看看您是否可以找到适用于这些 DIV 元素的任何position: absolute
,然后将其删除。此外,您应该使用 class="delete"
而不是 id="delete"
,因为多个元素不应共享相同的 id
属性。
要进行测试,您可以尝试:
<div id="delete" style="text-align: center; position: block;">