将css添加到表单中


Adding css to a form

我正在尝试将CSS添加到我的表单中,但不知道如何做到这一点。该表单是在php和MySQL中创建的,在浏览器中看起来像:http://gyazo.com/5d099ead9bd6ea83859a5114b2438748

我需要将文本和下拉列表对齐,使它们在整个过程中相等,并添加一些间距。有人帮过CSS吗?

html当前:

  <div class="wrap">
              <img src="/images/logo.png" alt="Highdown logo" />
              <h1>Entry form</h1> 
            </div>

css当前:

.wrap {
                position: relative;
                }

表格是用这个生成的:

if ($event_result = $con->query("SELECT Event.Name FROM event")) {  
                echo "<form method ='"POST'" action='"save.php'"> ";
                            while ($row = $event_result->fetch_assoc()) {               
                            echo $row['Name']. ' ';
                                if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
                                    "FROM Student, Teacher " .
                                        "WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {
                                    if ($student_result->num_rows) {                                                                                
                                                echo "<select name ='". $row['Name']."'>";  
                                                    while ($row1 = $student_result->fetch_assoc()) {
                                                    echo '<option value="" style="display:none;"></option>';
                                                    echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";
                                                }
                                                echo "</select> <br />";                    
                                    }                                                                   
                                }
                            }   
                        echo '<input type="submit" value ="Submit">';
                        echo '<input type="reset" value ="Reset">';
                        echo '<input type="button" value = "Add student" onclick="location.href=''http://localhost/sportsday/addstudent.php''">';
                        echo '<input type="button" value = "Delete student">';
                echo "</form>"; 
            }

使用

<form>
    <table>
      <tr> //1st Table row
        <td></td> //Table column data
        <td></td> //table column data
      </tr> //1st row ends
      <tr> // 2nd Table row
        <td></td> //Table column data
        <td></td> //table column data
      </tr> //2nd row ends
    </table>
</form>

这将为您提供更好的表单布局。

我没有尝试,因为我没有数据库

        //Query to display all events                                                  
                if ($event_result = $con->query("SELECT Event.Name FROM event")) {                     
                        echo "<form method ='"POST'" action='"save.php'"> ";
                                echo '<table>';
                                        echo '<tr>';
                                        echo '<td>';
                                                while ($row = $event_result->fetch_assoc()) {                          
                                                        echo $row['Name']. ' ';
                                        echo '</td>';          
                                                if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
                                                        "FROM Student, Teacher " .
                                                                "WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {

                                                        if ($student_result->num_rows) {                                                                                                                                                                                                                                       
                                                                echo '<td>';
                                                                echo "<select name ='". $row['Name']."'>";     
                                                                        while ($row1 = $student_result->fetch_assoc()) {

                                                                        echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";       
                                                                }              
                                                                echo "</select> <br />";
                                                                echo '</td>';          
                                                                echo '</tr>';                                                                          
                                                        }                                                                                                                                      
                                                }
                                        }
                                        echo '</table>';                                               
                                        echo '<input type="submit" value ="Submit">';
                                        echo '<input type="reset" value ="Reset">';
                                        echo '<input type="button" value = "Add student" onclick="location.href=''http://localhost/sportsday/addstudent.php''">';
                                        echo '<input type="button" value = "Delete student">';                                         
                        echo "</form>";
                        }


?>

您可以直接在css 中编写

form {
  ⋮ declare css
}

或命名以形成

form[name="value"]{
    ⋮ declare css
}

或在表单上添加任何类别或id

#formid{
    ⋮ declare css
}
.formclass{
       ⋮ declare css
} 

首先,检查数据库。。。可能存在与表格输出无关的另一个问题。

因此,首先删除表标记。。并检查它是否工作?

然后尝试HTML表格标签

否则,给我一个示例数据库.sql文件,并在谷歌驱动器或共享驱动器上完成PHP代码。

这样我就可以检查并确定问题出在哪里了?