我是css和php的新手,我想通过php从db检索信息并将其显示给用户,一切正常,但问题在于UI部分enter image description here 我的代码是
<?
$result=mysql_query($query) or die (mysql_error());
echo "<div class='container'>";
while($row =mysql_fetch_array($result))
{
echo "<div class='row custom1'>";
echo "<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'><a href='showit.php' class='kk'>";
echo '<p class="head1">QUESTION:',$row['title'],'</p><p clsss="head2" style="font-size:20px;"></br>Tags:',$row['tags'],'</br>Posted by:',$row['posted'],'</br>Posted On:',$row['postedon'],'</p>';
echo "</div>";
}
echo "</div>";
?>
有没有办法正确对齐div?
答案 0 :(得分:1)
这是因为你错过了第二个div的结束</div>
和你的while循环中的结束</a>
,使得一群孩子互相生成,而不是容器父的内部节点,改为使用这个循环:
$result=mysql_query($query) or die (mysql_error());
echo "<div class='container'>";
while($row =mysql_fetch_array($result))
{
echo "<div class='row custom1'>";
echo "<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'>";
echo "<a href='showit.php' class='kk'>";
echo "<p class=\"head1\">QUESTION:".$row['title']."</p>";
echo "<p class=\"head2\" style=\"font-size:20px;\">";
echo "</br>Tags:".$row['tags']."</br>Posted by:".$row['posted']."</br>Posted On:".$row['postedon'];
echo "</p>";
echo "</a>";
echo "</div>"; //col-sm-12
echo "</div>"; //row custom1
}
echo "</div>";
答案 1 :(得分:0)
小心你没有关闭所有标签。我看到了
<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'><a href='showit.php' class='kk'>
未关闭。
请进入浏览器页面并检查元素,确认它们是如何关闭的。