将css添加到表单中

时间:2015-02-12 07:26:22

标签: php html css forms

我正在尝试将CS​​S添加到我的表单中,但不确定如何执行此操作。表单在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>"; 
            }

4 个答案:

答案 0 :(得分:2)

使用

<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>

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

答案 1 :(得分:1)

这应该工作我没有尝试,因为我没有数据库     

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

                        }





?>

答案 2 :(得分:0)

你可以直接用css写

form {
  ⋮ declare css
}

或给表格命名

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

或在表单上添加任何类或ID

#formid{
    ⋮ declare css
}

.formclass{
       ⋮ declare css
} 

答案 3 :(得分:0)

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

那么,首先删除Table Tag ..并检查它是否正常工作?

然后尝试HTML TABLE TAG

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

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