为 php 生成的 html table 设置样式

Styling an html table generated with php

所以我有这个 html table 我想设计样式。它有 php 给 table 它的值(这是一堆 select 字段)

我可能做错了什么,php 工作正常(它向我的数据库发送数据)但我不能用 css 设置它的样式。

<form action='processes.php' method='GET'>
    <table>
        <?php
        echo "<tr>";
        echo "<th>COURSE NUMBER</th>";

        foreach($course_list as $cc){
            $c = str_replace("_", " ", $cc);
            echo "<th>$c</th>";
        }

        echo "</tr>";  

        while($record = mysqli_fetch_assoc($user_subject_results)){

            echo "<tr>";                
            $subjects[] = $record['Course']; //stores every subject in a list
            $_SESSION['Subjects'] = $subjects; //store the list in a session variable so i can use it in my processes page.             
            echo "<td>".$record['Course']."</td>";  

            foreach($course_list as $cc){

                echo "<input type = 'hidden', name = ".'pk'.$record['Course']." value = ".$user.'_'.$record['Course']." />";                    
                echo "<td><select name =".$kc.$record['Course'].">";                    

                foreach($eval_list as $opt){
                    echo "<option value = '".$opt."'>".$opt."</option>";
                }

                "</select>
                </td>";
            }

            echo "</tr>";
        }
        ?>
    </table>
    <input type='submit' value='submit' />
</form>

这可能与我放置“”的位置有关?我好迷茫

编辑:CSS(糟糕!)

table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #ffffff;

好吧,老实说,我会先将 table 标签更改为 div 标签。现在这只是我,但这使样式更容易一些。这是我将如何开始的示例:

外部样式sheetstyle.css

    #main-div{
        /*All Your styles Go Here if you dont know how to style refer to w3schools.org*/

    }

    .header{
        /*All Your styles Go Here if you dont know how to style refer to w3schools.org*/

    }

    .courses-head{
        /*Give this a width such as width:10%; or 20% or whatever 
        example:
        width:20%;
        Add more styles if necessary
        */
    }

    .courses-list{
        /*Give this a width such as width:10%; or 20% or whatever 
        example:
        width:20%;
        Add more styles if necessary
        */
    }

您的实际页面:

<!--This goes in the Head -->
    <link rel="stylesheet" href="/path/to/styles.css">

    <form action='processes.php' method='GET'>
        <div id=main-div>
            <?php
            echo "<div class='header'>";
            echo "<div class=courses-head>COURSE NUMBER</div>";

            foreach($course_list as $cc){
                $c = str_replace("_", " ", $cc);
                echo "<div class='course-list'>$c</div>";
            }

            echo "</div>";  

只要继续遵循我开始将所有 Table 元素更改为 .. 相信我,在一天结束时,它会让您的生活变得更加轻松。我曾经做过同样的事情。