【发布时间】:2018-09-25 09:40:30
【问题描述】:
我的网站上有一个表格,其中包含以下列:用户、标题、描述、加入、更新、删除。
“用户”列的宽度以及“标题”列的宽度都太大了。我需要 CSS 的帮助来将它们设置为更小而不影响其他列的宽度,因为它们是完美的。
我的代码:
<?php
echo "<table>
<tr>
<th>User</th>
<th>Title</th>
<th>Description</th>
<th></th>
<th>Join</th>
<th>Update</th>
<th>Delete</th>
</tr>";
while ($record = mysql_fetch_array($myData))
{
echo "<form action=findGroup.php method=post>";
echo "<div class=joinLink>";
echo "<tr>";
echo "<td>" . "<input type=text name=name value='" . $record['form_user'] . "'/> </td>";
echo "<td>" . "<input type=text name=name value='" . $record['form_name'] . "'/> </td>";
echo "<td>" . "<input type=text name=description value='" . $record['form_description'] . "'/> </td>";
echo "<td>" . "<input type=hidden name=hidden value='" . $record['form_id'] . "'/></td>";
echo "<td><a class=joinLink type=text name=join href='http://localhost:3000'>Join</a></td>";
echo "<td>" . "<input type=submit name=update value='Update" . "'/> </td>";
echo "<td>" . "<input type=submit name=delete value='Delete" . "'/> </td>";
echo "</tr>";
echo "</div>";
echo "</form>";
}
echo "</table>";
CSS:
table {
width: 100%;
font: 17px/1.5 Arial, Helvetica,sans-serif;
text-align: centre;
align: centre;
}
input {
width: 100%;
font: 13px/1.5 Arial, Helvetica,sans-serif;
text-align: centre;
align: centre;
height: auto;
overflow: hidden;
}
th {
align: centre;
text-align: centre;
background-color: #4D5960;
color: white;
}
tr {
background-color: #f2f2f2
}
input[type="text"]{
width:100% !important;
line-height:30px;
box-sizing:border-box;
}
a[type="text"]{
width:100% !important;
line-height:30px;
box-sizing:border-box;
}
【问题讨论】:
-
这不是一个真正的 PHP 问题,尽管您使用 PHP 来生成它。您应该将生成的 HTML 添加到问题中。
-
不要使用已弃用且不安全的
mysql_*-函数。它们自 PHP 5.5(2013 年)以来已被弃用,并在 PHP 7(2015 年)中完全删除。请改用 MySQLi 或 PDO。 -
您还应该为每个
name属性指定唯一的名称。处理您的表单后,您将无法区分form_user和form_name。 -
@chris85 感谢您的建议。
-
@MagnusEriksson 我知道代码被贬值了,很快就会修复!
标签: php html css html-table width