2017-11-18 155 views
-1

我在PHP中回显表。不必手动设置表格的样式,我怎样才能让它为我在style.css中列出的表格选择相同的样式?将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

您已包括在文件中的CSS代码你在哪里打印表格吗? – Varun

回答

0

风格应该在呼应表工作太就像代码HTML表格。确保你已经包含了css文件,删除了浏览器的缓存(或者按下键盘上的ctrl + f5),删除了框架的缓存(可能是重新启动服务器以删除缓存)。

-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

+0

问题中的CSS使用类型选择器,而不是类选择器。 – Quentin

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"> ';