dongnao3990 2015-10-24 06:32
浏览 5
已采纳

为什么div会向左边缘运行?

I am new to css and php, i want to retrieve information from db via php and display it to the user, all working fine but problem is with the UI part enter image description here and my code is

<?
$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>";
?>

is there any way to align the divs properly?

  • 写回答

2条回答 默认 最新

  • dtxooq1020 2015-10-24 06:39
    关注

    it's because you're missing the closing </div> for the second div and the closing </a> in your while loop making a bunch of children of each other, rather than inner nodes of the container parent, use this loop instead:

    $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>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dti3914 2015-10-24 06:41
    关注

    By careful you are not closing all tags. I saw that

    <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'>
    

    is not closed.

    Please go into your browser page and inspect the elements an verify how they are closed.

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VB6.0中PICTUREBOX加载本地图片无法显示
  • ¥100 关于游戏app session获取的问题
  • ¥15 MYSQL数据库建表
  • ¥15 爬虫程序爬取TTGChina网站文章代码
  • ¥35 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
  • ¥15 如何用下图方法在AMESim中搭建离心泵模型
  • ¥15 C#连接服务器,请求时报Ssl/Tsl未能建立安全通道
  • ¥15 xcode15build的c++ dylib在10.15上不兼容
  • ¥15 CPLD如何实现在线逻辑分析
  • ¥15 控制面板卸载无权限!!