如何删除联系表中的多余填充?

时间:2019-06-28 19:32:41

标签: html twitter-bootstrap forms

我不太了解HTML / Bootstrap,因此在联系表方面需要帮助。

我无法删除表单中多余的填充,而且我想将提交按钮设为红色和全角。我也想知道,即使我减小了输入的宽度,在名称和电话下方仍可以找到“电子邮件”和“正在考虑”。

Here is a fiddle that I did.

非常感谢您的帮助。

<div class="col-md-3">
    <div class="form-group">
      <label for="form_lastname">Your Phone *</label>
      <input id="form_lastname" type="text" name="surname" class="form-control" required="required" data-error="Lastname is required.">
      <div class="help-block with-errors"></div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-3">
    <div class="form-group">
      <label for="form_email">Email *</label>
      <input id="form_email" type="email" name="email" class="form-control" required="required" data-error="Valid email is required.">
      <div class="help-block with-errors"></div>
    </div>
  </div>

2 个答案:

答案 0 :(得分:1)

需要注意的几件事:

  • 引导程序中的行有12列,因此,如果您希望行中的元素占据整个宽度,则它们的大小应总计为12。您的输入为col-md-3,我将其设置为col-md-6
  • 您可以通过将其设为btn-block类来使按钮全宽。由于前面提到的内容,给它col-md-20类没有意义,所以我将其命名为col-md-12
  • 通过为按钮提供btn-danger类可以将按钮变为红色。
  • 默认情况下,引导程序中的容器通常会尽可能地宽。我为您的容器提供了以下属性:max-width: 600px。也许更整洁的方法是使用媒体查询来根据屏幕大小为其提供不同的宽度,但这取决于您要执行的操作。

以下是应用了这些更改的解决方案:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<html>

<head>
  <title>Contact Form</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  <link href='https://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
  <link href='custom.css' rel='stylesheet' type='text/css'>
</head>

<body>

  <div class="container" style="border-radius:5px;background-color:#f56b00;max-width: 600px">
    <div class="row">
      <div class="col-xl-8 offset-xl-2 py-5">
        <h1>
          <font color="#ffffff">Schedule a Call With Us Today</font>
        </h1>

        <p class="lead"></p>
        <form id="contact-form" method="post" action="contact.php" role="form">
          <div class="messages"></div>
          <div class="controls">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_name">Your Name *</label>
                  <input id="form_name" type="text" name="name" class="form-control" required="required" data-error="Firstname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_lastname">Your Phone *</label>
                  <input id="form_lastname" type="text" name="surname" class="form-control" required="required" data-error="Lastname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_email">Email *</label>
                  <input id="form_email" type="email" name="email" class="form-control" required="required" data-error="Valid email is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label for="form_need">Considering *</label>
                  <select id="form_need" name="need" class="form-control" required="required" data-error="Please specify your need.">
                    <option value="Request quotation">Buying</option>
                    <option value="Request order status">Selling</option>
                    <option value="Request copy of an invoice">Other</option>
                  </select>
                  <div class="help-block with-errors"></div>
                </div>
              </div>
            </div>
            <div class="col-md-12">
              <input type="submit" class="btn btn-success btn-send btn-danger btn-block" value="Submit">
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.min.js" integrity="sha256-dHf/YjH1A4tewEsKUSmNnV05DDbfGN3g7NMq86xgGh8=" crossorigin="anonymous"></script>
  <script src="contact.js"></script>
</body>

</html>

我认为您应该阅读以下内容:

如果要连续显示所有字段:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<html>

<head>
  <title>Contact Form</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  <link href='https://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
  <link href='custom.css' rel='stylesheet' type='text/css'>
</head>

<body>

  <div class="container" style="border-radius:5px;background-color:#f56b00;max-width: 600px">
    <div class="row">
      <div class="col-xl-8 offset-xl-2 py-5">
        <h1>
          <font color="#ffffff">Schedule a Call With Us Today</font>
        </h1>

        <p class="lead"></p>
        <form id="contact-form" method="post" action="contact.php" role="form">
          <div class="messages"></div>
          <div class="controls">
            <div class="row">
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="form_name">Your Name *</label>
                  <input id="form_name" type="text" name="name" class="form-control" required="required" data-error="Firstname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="form_lastname">Your Phone *</label>
                  <input id="form_lastname" type="text" name="surname" class="form-control" required="required" data-error="Lastname is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="form_email">Email *</label>
                  <input id="form_email" type="email" name="email" class="form-control" required="required" data-error="Valid email is required.">
                  <div class="help-block with-errors"></div>
                </div>
              </div>
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="form_need">Considering *</label>
                  <select id="form_need" name="need" class="form-control" required="required" data-error="Please specify your need.">
                    <option value="Request quotation">Buying</option>
                    <option value="Request order status">Selling</option>
                    <option value="Request copy of an invoice">Other</option>
                  </select>
                  <div class="help-block with-errors"></div>
                </div>
              </div>
            </div>
            <div class="col-md-12">
              <input type="submit" class="btn btn-success btn-send btn-danger btn-block" value="Submit">
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.min.js" integrity="sha256-dHf/YjH1A4tewEsKUSmNnV05DDbfGN3g7NMq86xgGh8=" crossorigin="anonymous"></script>
  <script src="contact.js"></script>
</body>

</html>

答案 1 :(得分:0)

我对您想要的东西感到很困惑,但是我做了我从小提琴中的问题中了解的事情:

https://jsfiddle.net/h2yjfund/

您的输入字段被堆叠,因为您开始了一个新的行div。我把它们都放在同一行。我还按照您的要求编辑了提交按钮,并将标头更改为纯粹居中以使其完全匹配。

我不太确定填充的含义,但是如果您指的是框之间的多余空间,那么您只需要使用margin:0px来调整元素的边距即可;或您想要的许多像素。

style="margin:5px;"

我将所有样式都添加为内联样式,因为您没有提供样式表。希望这可以帮助。让我知道你是否有疑问。