首页 > 解决方案 > HTML/CSS 输入字段缩小

问题描述

您好我正在尝试使用 Django 为在线商店开发网站。在我的结帐表单中,地址、国家、邮政编码、电话等输入字段正在缩小。但是,状态字段(具有选项的字段不会缩小)。即使在我的登录和注册表单中,输入字段也在缩小。谁能告诉我为什么会这样?

我的 checkout.html:

{% extends 'base.html' %} 
{% load crispy_forms_tags %}
{% block content %}
  <!DOCTYPE html>
  <html lang="en">
    <head>
      <!-- Required meta tags -->
      <meta charset="utf-8" />
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, shrink-to-fit=no"
      />

      <!-- Bootstrap CSS -->
      <link
        rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
        integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
        crossorigin="anonymous"
      />

      <!-- Custom styles for this template -->
      <link href="./css/form-validation.css" rel="stylesheet" />
    </head>
    <div class="container">
        <div class="row">
          <body class="bg-white">
            <div class="container">
              <div class="py-5 text-center">
                <img
                  class="d-block mx-auto mb-4"
                  src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg"
                  alt=""
                  width=""
                  height=""
                />
                <h2>Checkout</h2>
              </div>

              <div class="row">
                <div class="col-md-4 order-md-2 mb-4">
                  <h4 class="d-flex justify-content-between align-items-center mb-3">
                    <span class="text-muted">Your cart</span>
                    <span class="badge badge-secondary badge-pill">{{ request.session.items_total }}</span>
                  </h4>
                  <ul class="list-group mb-3">
                    {% for item in cart.cartitem_set.all %}
                      <li
                        class="list-group-item d-flex justify-content-between lh-condensed"
                      >
                        <div>
                          <h6 class="my-0">{{ item.product.name }}</h6>
                          <small class="text-muted">Brief description</small>
                        </div>
                        <span class="text-muted">${{ item.product.price }}</span>
                      </li>
                    {% endfor %}
                    <li class="list-group-item d-flex justify-content-between bg-light">
                      <div class="text-success">
                        <h6 class="my-0">Promo code</h6>
                        <small>VCA101</small>
                      </div>
                      <span class="text-success">-$5</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between">
                      <span>Total (USD)</span>
                      <strong>${{ cart.total }}</strong>
                    </li>
                  </ul>

                  <form class="card p-2">
                    <div class="input-group">
                      <input
                        type="text"
                        class="form-control"
                        placeholder="Promo code"
                      />
                      <div class="input-group-append">
                        <button type="submit" class="btn btn-secondary">Redeem</button>
                      </div>
                    </div>
                  </form>
                </div>
                <div class="col-md-8 order-md-1">
                  <h4 class="mb-3">Billing address</h4>
                  <form class="needs-validation" novalidate>
                    <div class="row">
                      <div class="col-md-6 mb-3">
                          <div class="content-section">
                              <form method="POST" action=''>
                                {% csrf_token %}
                                  <fieldset class="form-group">   
                                    {{ address_form|crispy }}
                                  </fieldset>
                                </form>
                          </div>



            </div>

            <!-- Bootstrap core JavaScript
            ================================================== -->
            <!-- Placed at the end of the document so the pages load faster -->
            <script
              src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
              integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
              crossorigin="anonymous"
            ></script>
            <script
              src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
              integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
              crossorigin="anonymous"
            ></script>
            <script
              src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
              integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
              crossorigin="anonymous"
            ></script>
            <script
              src="https://cdnjs.cloudflare.com/ajax/libs/holder/2.9.4/holder.min.js"
              integrity="sha256-ifihHN6L/pNU1ZQikrAb7CnyMBvisKG3SUAab0F3kVU="
              crossorigin="anonymous"
            ></script>
          </body>
        </div>
      </form>
    </div>
  </div>
</div>
<footer class="py-5 bg-dark bottom">
  <div class="container">
    <p class="m-0 text-center text-white">Copyright &copy; MyShop 2020</p>
  </div>
  <!-- /.container -->
</footer>
</html>

{% endblock %}

我的 main.css:



body {
  background: #FFFFFF;
  min-height: 100vh;
}


body { padding-top: 70px; }

input[type=text]:focus { width: 10px; }

/*registration form*/
.divider-text {
    position: relative;
    text-align: center;
    margin-top: 15px;
    margin-bottom: 15px;
}
.divider-text span {
    padding: 7px;
    font-size: 12px;
    position: relative;   
    z-index: 2;
}
.divider-text:after {
    content: "";
    position: absolute;
    width: 100%;
    border-bottom: 1px solid #ddd;
    top: 55%;
    left: 0;
    z-index: 1;
}

.btn-facebook {
    background-color: #405D9D;
    color: #fff;
}
.btn-twitter {
    background-color: #42AEEC;
    color: #fff;
}

input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}

/*checkout form*/

标签: htmlcss

解决方案


我猜状态的输入字段在输出的 HTML 中呈现为 a<select>...</select>而不是标签。<input ... />你能证实吗?

如果是这样,您可能需要调整 CSS 以将定义的样式不仅应用于input元素,还应用于select元素。

也许是这样的:

input[type=text], select {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}

这对你有帮助吗?


推荐阅读