2017-11-18 8 views
-1

私はPHPのエコーテーブルを持っています。テーブルを手動でスタイルするのではなく、style.cssにリストされているテーブルと同じスタイルを取得するにはどうしたらいいですか?以下はエコーテーブルにstyle.cssを適用する

、私はエコーテーブル用のコードとの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>"; 

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

はスタイルがエコーされたテーブルの上に動作するはずCSSあまりにも同じように持っています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>"; 

//ちょうど限り、上記の.cssコードは、それが動作するはずですあなたのテーブルと同じファイル内にあるように、単一のqotaと表に

+0

質問のCSSは、クラスセレクタではなく、タイプセレクタを使用しています。 – Quentin

0

をクラス名を置きます。

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"> '; 
関連する問題