html - 在 PHP/HTML 中对齐信息

标签 html css

我有这段代码,目前显示的信息如下:

 <?php
    mysql_connect("localhost","example","password") or die("Could not connect to localhost");
mysql_select_db("exampledb") or die( "Could not connect to database");
$result = mysql_query("SELECT * FROM tablexample");

echo "<b>" . "Name"  . "</b>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . "<b>" . "Number" . "</b>";
echo "<br/>";
echo "<br/>";
while ($row = mysql_fetch_array($result))
  {
echo  ucwords($row['name']) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . ucwords($row['number']) . "<br>"; 
echo "<hr width='20%'>";
  }
?>


Name              Number

B              (888) 888-3545
C         (098) 545-4354
Cl               (888) 888-3545
Da              (888) 888-3545
H               (888) 888-3545
H               (888) 888-3545
Khzdf              (888) 888-3545

但我希望它们像这样对齐(它应该覆盖每个名称有多少个字母并具有相同的空格:

Name              Number

B              (888) 888-3545
C              (098) 545-4354
Cl             (888) 888-3545
Da             (888) 888-3545
H              (888) 888-3545
H              (888) 888-3545
Khzdf          (888) 888-3545

-- 这是用 CSS 还是 PHP 完成的?

最佳答案

您是否考虑过使用表格?表格很棒....用于显示结构化数据

<table>
    <thead>
        <tr>
            <th>Column1</th>
            <th>column</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Column1 data</td><td>column 2 data</td>
        </tr>
    </tbody>
</table>

关于html - 在 PHP/HTML 中对齐信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15724926/

相关文章:

html - 顶部输入的 float 标签

html - CSS - 调用 element[attribute^=value] 后未应用 border-X-color 的原因

css - 如何将图像向下移动几个像素?

CSS:如何制作带有 repeat-x 背景和提示的 !100% 标题

javascript - 使用 div 制作 Facebook 风格的头像

jquery - <tr> 上的 slideToggle() 导致 "jump"

javascript - JQuery noConflict 运行两个版本

javascript - 如何判断 jQuery 节点是否位于其父节点的开头?

html - 如何限制 KendoUI 网格可以拥有的行数?

javascript - 如何对齐 <select> 标签下方的图片?