【问题标题】:Two tables align in different ways with the same stylesheet两个表格以不同的方式与相同的样式表对齐
【发布时间】:2020-08-02 19:45:45
【问题描述】:

我有两张桌子。一个是用 html(和一点点 php)创建的,而另一个是由两个 php-loops 创建的。

首先是样式表:

.statistics {
    font-family: Arial, monospace;
    font-size: 36px;
    margin-left: 5%;
    width: 90%;
}

.statistics tr {
    line-height: 50px;
}

.statistics th {
    text-align: center;
}

.statistics td {
    text-align: center;
}

button {
    margin-left: 25%;
    width: 50%;
    height: 40px;
    border: none;
    border-radius: 20px;
    font-family: Arial, monospace;
    font-size: 20px;
}

下表正确对齐:

<table class="statistics">
        <tr>
            <th>Benutzer</th>
            <th>Artikel</th>
            <th>Reservierungen</th>
        </tr>
        <tr>
            <td><?php echo $client->statistic_getAmount();?></td>
            <td><?php echo $articles->statistic_getAmount();?></td>
            <td><?php echo $reservations->statistic_getAmount();?></td>
        </tr>
        <tr>
            <th>Seiten (.php)</th>
            <th>Datenbankeinträge</th>
            <th>Zeilen mit Code</th>
        </tr>
        <tr>
            <td>18</td>
            <td>27</td>
            <td>4407+</td>
        </tr>
    </table>

虽然这个没有正确对齐:

<form method="post" action="webinterface.php" class="perms">
        <table class="statistics">
            <tr>
                <th>Benutzer</th>
                <?php
                foreach ($permgroupa as $group) {
                    echo "<th>".$group."<th>";
                }
            echo "</tr>";
            $users = $client->getUsers();

            while ($row = mysqli_fetch_assoc($users)) :?>
                <tr>
                    <td><?php echo $row['username'];?></td>
                    <?php foreach ($permgroupa as $group) : ?>
                        <td><input type="checkbox" name="<?php echo $group;?>-<?php echo $row['username'];?>" <?php if ($perms->hasPermission($row['username'], $group)) {echo "checked";}?>></td>
                    <?php endforeach;?>
                </tr>
            <?php endwhile;?>
    </table><button type="submit" class="btnalter" name="alterrights">Rechte aktualisieren</button></form>

The tables in action

有人知道,为什么它们以不同的方式对齐吗?

【问题讨论】:

    标签: php html css forms html-table


    【解决方案1】:

    1 - 不要将表格放在表单中

    2 - 第一个和第二个表的列数不一样

    【讨论】:

    • 1 - 我应该如何将复选框放在该网格方案中? 2 - 第二个表中的两个 foreach 循环都创建 2 列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    相关资源
    最近更新 更多