【问题标题】:Adding css to a form将css添加到表单
【发布时间】:2015-04-12 20:15:11
【问题描述】:

我正在尝试将 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>"; 
            }

【问题讨论】:

    标签: php html css forms


    【解决方案1】:

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

    所以,首先删除Table Tag..并检查它是否工作?

    然后在 HTML TABLE TAG 中尝试

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

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

    【讨论】:

      【解决方案2】:

      这应该可行,因为我没有数据库,所以我没有尝试

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

      【讨论】:

        【解决方案3】:

        你可以直接用css写

        form {
          ⋮ declare css
        }
        

        或为表格命名

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

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

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

        【讨论】:

          【解决方案4】:

          使用

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

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

          【讨论】:

          • 会这样做,只是为了确认,表格标签超出了表单标签?那么 tr 和 td 标签呢?他们会在表格中去哪里
          • @cbaker only &lt;tr&gt;, &lt;thead&gt;, &lt;tbody&gt;&lt;tfoot&gt; 标签允许在 &lt;table&gt; 元素内。因此,&lt;form&gt; 应该包裹整个 &lt;table&gt;
          • 刚刚尝试添加表格,产生了错误的输出,你能看出哪里错了吗? gyazo.com/3630123d3be2c6962d658a7231c932d2 谢谢,获取正确表格时遇到问题
          • @cbaker 你能把代码放在我可以使用它的地方吗..?并将表单标签放在表格外面而不是里面看我上面的代码
          • 我不知道有什么地方可以像你问的那样编辑:(当前代码:gyazo.com/8e33ca69396d0a9138a22ae08680ae09,输出看起来像:gyazo.com/cfd6b1c7e393a284fde82e982dcfc62b(名称应该在下拉列表中)跨度>
          猜你喜欢
          • 2017-11-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-28
          • 2013-08-04
          • 2018-03-16
          • 2017-04-12
          • 1970-01-01
          • 2012-09-30
          相关资源
          最近更新 更多