【问题标题】:How to make a table to organize buttons in PHP如何制作表格以在 PHP 中组织按钮
【发布时间】:2015-09-07 02:02:38
【问题描述】:

我有这段代码,它从目录中的文件创建按钮。我需要将它们组织在一个有 4 列的表格中。我该怎么做?

这是我的代码:

$handle = opendir('mydirectory');

if($handle){
    while(($entry = readdir($handle)) !== false){
        if($entry != '.' && $entry != '..' && $entry != '.htaccess'){

       echo "<button onclick=\"location.href='mydirectory/$entry'\"    style=\"background-color: #660000;\"><p style=color:white;>$entry</button><br>";

        }
    }
    closedir($handle);

【问题讨论】:

  • 如果你坚持使用&lt;table&gt;,就会有很多&lt;tr&gt;&lt;td&gt;代码。相反,我建议您使用 CSS float: left 让浏览器自动排列您的按钮。
  • @Raptor:这可能是一个体面答案的核心。

标签: php html tabular


【解决方案1】:

采用 @Raptor 在 cmets 中提到的内容,您可以执行以下操作:

<style>
#buttons{
  width: 300px;
  float:left;
}
</style>
<div id="buttons">
<?php
for($i=0;$i <=10; $i++){
  echo "<button>Button $i</button>";
}
?>
</div>

【讨论】:

  • 你只需要设置 CSS 。
  • 这正是我希望我的按钮组织的方式。谢谢你。不过我确实有一个问题,我的按钮大小不同,我希望它们有条理,所以它们之间有一点空间,以便它们可以对齐。我该怎么做?
  • @Alchemist - margin-right:5px; 按钮上的 css 样式?
猜你喜欢
  • 2021-04-06
  • 2023-03-15
  • 2021-12-27
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-21
相关资源
最近更新 更多