Php 将style.css应用于echo表

Php 将style.css应用于echo表,php,html-table,echo,Php,Html Table,Echo,我在PHP中创建了echo表。不必手动设置表格的样式,如何让它为我在style.css中列出的表格选择相同的样式 下面是echo表的代码和style.css中表的代码 echo "<table>"; echo "<thead>". "<tr>". '<th>ETF Ticker</th>'. '<th>ETF Name</th>

我在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>";

该样式也应该像html表一样适用于回显表。确保已包含css文件、删除浏览器缓存(或按键盘上的ctrl+f5)、删除框架缓存(可能重新启动服务器以删除缓存)。

echo”“;
“回声”。
"".
“ETF股票代码”。
“ETF名称”。
“1年方向%”。
“持有名称”。
“工业”。
总数的%”。
"".
"";
//循环以显示结果
while($row=mysqli\u fetch\u assoc($result))
{
回声“;
回显“$row['ETF']”;
回显“$row['ETF NAME']”;
回显“$行['1年方向%”;
回显“$row['Holding Name']”;
回显“$行[“行业]”;
回显“$行[“持股百分比]”;
"";
}
回声“;

//只要将类名放在带有单个qota的表中,就可以了,只要上面的.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>';
echo'
桌子{
/*表仍然需要在标记中使用“cellspacing=”0“*/
边界塌陷:塌陷;
边界间距:0;
边缘:0.1.5em;
宽度:100%;
显示:块;
溢出-x:自动;
空白:nowrap;
}
泰德{
字体大小:粗体;
边界:2px;
背景色:#992c29;
颜色#F7F4;
文本对齐:居中;
}
';
或者如果您将.css文件保存在其他地方:

echo ' <link rel="stylesheet" type="text/css" href="path/to/your/css_file.css"> ';
echo';

您在打印表格的文件中包含了CSS代码,对吗?问题中的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>';
echo ' <link rel="stylesheet" type="text/css" href="path/to/your/css_file.css"> ';