我在PHP中使用echo表。而不是必须手动设置表格,我怎样才能让它为我在style.css中列出的表格选择相同的样式?
下面,我有echo表的代码和style.css中表的代码
echo "<table>";
echo "<thead>".
"<tr>".
'<th>ETF Ticker</th>'.
'<th>ETF Name</th>'.
'<th>1 Yr Direction %</th>'.
'<th>Holding Name</th>'.
'<th>Industry</th>'.
'<th>% of total</th>'.
"</tr>".
"</thead>";
// Loop to show results
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['ETF'] . "</td>";
echo "<td>" . $row['ETF NAME'] . "</td>";
echo "<td>" . $row['1 YR Direction %'] . "</td>";
echo "<td>" . $row['Holding Name'] . "</td>";
echo "<td>" . $row['Industry'] . "</td>";
echo "<td>" . $row['Percent Holdings'] . "</td>";
"</tr>";
}
echo "</table>";
CSS
table {
/* tables still need 'cellspacing="0"' in the markup */
border-collapse: collapse;
border-spacing: 0;
margin: 0 0 1.5em;
width: 100%;
display: block;
overflow-x: auto;
white-space: nowrap;
}
thead {
font-weight: bold;
border: 2px;
background-color: #992c29
color #f7f4f4;
text-align: center;
}
答案 0 :(得分:0)
样式应该在echo表上工作,就像html表一样。确保你已经包含了css文件,删除了浏览器的缓存(或者在键盘上按ctrl + f5),删除了框架的缓存(可能重启服务器以删除缓存)。
答案 1 :(得分:0)
只要上面的.css代码与你的表在同一个文件中就可以了。
echo '<style type="text/css">
table {
/* tables still need 'cellspacing="0"' in the markup */
border-collapse: collapse;
border-spacing: 0;
margin: 0 0 1.5em;
width: 100%;
display: block;
overflow-x: auto;
white-space: nowrap;
}
thead {
font-weight: bold;
border: 2px;
background-color: #992c29;
color #f7f4f4;
text-align: center;
}
</style>';
或者如果您将.css文件保存在其他地方:
echo ' <link rel="stylesheet" type="text/css" href="path/to/your/css_file.css"> ';
答案 2 :(得分:-1)
echo "<table class='class_name'>";
echo "<thead>".
"<tr>".
'<th>ETF Ticker</th>'.
'<th>ETF Name</th>'.
'<th>1 Yr Direction %</th>'.
'<th>Holding Name</th>'.
'<th>Industry</th>'.
'<th>% of total</th>'.
"</tr>".
"</thead>";
// Loop to show results
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['ETF'] . "</td>";
echo "<td>" . $row['ETF NAME'] . "</td>";
echo "<td>" . $row['1 YR Direction %'] . "</td>";
echo "<td>" . $row['Holding Name'] . "</td>";
echo "<td>" . $row['Industry'] . "</td>";
echo "<td>" . $row['Percent Holdings'] . "</td>";
"</tr>";
}
echo "</table>";
//只需将类名称放在具有单个qota的表中