【问题标题】:Envelope contact form responsive issue信封联系表格响应问题
【发布时间】:2019-09-27 16:01:03
【问题描述】:

我的信封联系表有问题。它在桌面上工作得很好,但在使其响应时出现问题。现在似乎有一个溢出问题。我相信这与在 px 中使用宽度和高度尺寸有关。我一直在尝试在 % 中制作宽度和高度,并且还溢出:隐藏;但没有运气。如何使我的代码具有响应性,使其在移动设备和平板电脑上也能正常工作?

body,
div,
h1,
h2,
form,
fieldset,
input,
textarea,
footer,
p {
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
}

.turbotobias-contact-section-wrapper {
  background-color: #ffffff;
  color: #000000;
  font-family: open sans, Arial, sans-serif;
  height: 60vh;
  display: flex;
}

.turbotobias-contact-section-wrapper p {
  font-size: 24px;
}

#wrap {
  width: 530px;
  margin: 20px auto 0;
  height: 1000px;
}

h1 {
  margin-bottom: 20px;
  text-align: center;
  font-size: 35px;
  font-family: open sans, Arial, sans-serif;
  color: white;
}

#form-wrap {
  overflow: hideen;
  height: 447px;
  position: relative;
  top: 0px;
  transition: all 1s ease-in-out 0.3s;
}

#form-wrap:before {
  content: "";
  position: absolute;
  bottom: 128px;
  left: 0px;
  background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-before.png) !important;
  width: 530px;
  height: 317px;
}

#form-wrap:after {
  content: "";
  position: absolute;
  bottom: 0px;
  left: 0;
  background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-after.png) !important;
  width: 530px;
  height: 259px;
  z-index: 999;
}

#form-wrap.hide:after,
#form-wrap.hide:before {
  display: none;
}

#form-wrap:hover {
  height: 777px;
  top: -200px;
}

form {
  background: white;
  position: relative;
  top: 200px;
  overflow: hidden;
  height: 200px;
  width: 400px;
  margin: 0px auto !important;
  padding: 20px !important;
  border: 1px solid white;
  border-right: 3px;
  transition: all 1s ease-in-out 0.3s;
}

#form-wrap:hover form {
  height: 530px;
}

label {
  margin: 11px 20px 0 0;
  font-size: 15px;
  color: gray;
  text-transform: uppercase;
}

input[type="text"],
textarea {
  font: 14px normal uppercase, arial, serif;
  color: dimgray;
  background: none;
  width: 380px;
  height: 37px;
  padding: 0px 10px;
  margin: 0 0 10px 0;
  border: 1px solid #f8f5f1;
  border-radius: 5px;
}

textarea {
  height: 80px;
  padding-top: 14px;
}

textarea:focus,
input[type="text"]:focus {
  background: white;
}

#form-wrap input[type="submit"] {
  position: relative;
  font-family: open sans, Arial, sans-serif;
  font-size: 24px;
  color: gray;
  width: 100%;
  text-align: center;
  opacity: 0;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  border: none !important;
  transition: opacity 0.7s ease-in-out 0s;
}

#form-wrap:hover input[type="submit"] {
  z-index: 1;
  opacity: 1;
  transition: opacity 0.5s ease-in-out 1.3s;
}

.turbotobias-contact-row {
  display: flex;
  width: 80%;
  max-width: 1080px;
  margin: auto;
  padding-bottom: 50px;
  flex-direction: row;
  flex-wrap: wrap;
}

@media (max-width: 980px) {
  .turbotobias-contact-row {
    padding: 30px 0;
  }
}
   <div class='turbotobias-contact-section-wrapper'>
        <div class='turbotobias-contact-row'>
            <div id="wrap">
                <br><br><br>
                <div id="form-wrap">
                    <form>
                        <p>HEJ TURBOTOBIAS,</p>
                        <label for="email">Din besked:</label>
                        <textarea name="message" id="message" value="Your message"></textarea>

                        <p>VENLIG HILSEN,</p>
                        <label for="name">Navn:</label>
                        <input type="text" name="name" value="" id="">

                        <label for="email">Email:</label>
                        <input type="text" name="email" value="" id="email">

                        <input type="submit" name="submit" value="SEND MIN BESKED TAK!">
                        </form>
                        </div>
            </div>
        </div>
    </div>

【问题讨论】:

    标签: html css responsive-design media-queries overflow


    【解决方案1】:

    这是因为图像的固定宽度。我对您的 CSS 进行了一些更改以使其正常工作。

    这是更新后的小提琴:

    body,
    div,
    h1,
    h2,
    form,
    fieldset,
    input,
    textarea,
    footer,
    p {
      margin: 0;
      padding: 0;
      border: 0;
      outline: none;
    }
    
    .turbotobias-contact-section-wrapper {
      background-color: #ffffff;
      color: #000000;
      font-family: open sans, Arial, sans-serif;
      height: 60vh;
      display: flex;
    }
    
    .turbotobias-contact-section-wrapper p {
      font-size: 24px;
    }
    
    #wrap {
      width: 550px;
      margin: 20px auto 0;
      height: 1000px;
    }
    
    h1 {
      margin-bottom: 20px;
      text-align: center;
      font-size: 35px;
      font-family: open sans, Arial, sans-serif;
      color: white;
    }
    
    #form-wrap {
      overflow: hideen;
      height: 447px;
      position: relative;
      top: 0px;
      transition: all 1s ease-in-out 0.3s;
    }
    
    #form-wrap:before {
      content: "";
      position: absolute;
      bottom: 128px;
      left: 0px;
      background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-before.png) !important;
      width: 530px;
      height: 317px;
    }
    
    #form-wrap:after {
      content: "";
      position: absolute;
      bottom: 0px;
      left: 0;
      background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-after.png) !important;
      width: 530px;
      height: 259px;
      z-index: 999;
    }
    
    #form-wrap.hide:after,
    #form-wrap.hide:before {
      display: none;
    }
    
    #form-wrap:hover {
      height: 777px;
      top: -200px;
    }
    
    form {
      background: white;
      position: relative;
      top: 200px;
      overflow: hidden;
      height: 100px;
      width: 400px;
      margin: 0px auto !important;
      padding: 20px !important;
      border: 1px solid white;
      border-right: 3px;
      transition: all 1s ease-in-out 0.3s;
    }
    
    #form-wrap:hover form {
      height: 530px;
    }
    
    label {
      margin: 11px 20px 0 0;
      font-size: 15px;
      color: gray;
      text-transform: uppercase;
    }
    
    input[type="text"],
    textarea {
      font: 14px normal uppercase, arial, serif;
      color: dimgray;
      background: none;
      width: 380px;
      height: 37px;
      padding: 0px 10px;
      margin: 0 0 10px 0;
      border: 1px solid #f8f5f1;
      border-radius: 5px;
    }
    
    textarea {
      height: 80px;
      padding-top: 14px;
    }
    
    textarea:focus,
    input[type="text"]:focus {
      background: white;
    }
    
    #form-wrap input[type="submit"] {
      position: relative;
      font-family: open sans, Arial, sans-serif;
      font-size: 24px;
      color: gray;
      width: 100%;
      text-align: center;
      opacity: 0;
      background: none;
      cursor: pointer;
      border-radius: 3px;
      border: none !important;
      transition: opacity 0.7s ease-in-out 0s;
    }
    
    #form-wrap:hover input[type="submit"] {
      z-index: 1;
      opacity: 1;
      transition: opacity 0.5s ease-in-out 1.3s;
    }
    
    .turbotobias-contact-row {
      display: flex;
      width: 80%;
      max-width: 1080px;
      margin: auto;
      padding-bottom: 50px;
      flex-direction: row;
      flex-wrap: wrap;
    }
    
    @media (max-width: 980px) {
      .turbotobias-contact-row {
        padding: 30px 0;
        width: 100%;
      }
      #form-wrap:before,
      #form-wrap:after {
        width: 100%;
        background-size: contain!important;
        background-repeat: no-repeat!important;
      }
      #form-wrap:after {
        height: 220px;
        bottom: 30px;
      }
      #wrap {
        width: 445px;
      }
      form {
        width: 320px;
      }
    }
    
    @media (max-width: 480px) {
      #wrap {
        width: 320px;
      }
      #form-wrap:after {
        height: 240px;
      }
      form {
        height: 0;
        width: 90%;
      }
      input[type="text"],
      textarea {
        width: 100%;
      }
      .turbotobias-contact-section-wrapper p {
        font-size: 19px;
        text-align: center;
        margin-top: -20px;
        height: 60px;
      }
    }
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <div class='turbotobias-contact-section-wrapper'>
      <div class='turbotobias-contact-row'>
        <div id="wrap">
          <br><br><br>
          <div id="form-wrap">
            <form>
              <p>HEJ TURBOTOBIAS,</p>
              <label for="email">Din besked:</label>
              <textarea name="message" id="message" value="Your message"></textarea>
    
              <p>VENLIG HILSEN,</p>
              <label for="name">Navn:</label>
              <input type="text" name="name" value="" id="">
    
              <label for="email">Email:</label>
              <input type="text" name="email" value="" id="email">
    
              <input type="submit" name="submit" value="SEND MIN BESKED TAK!">
            </form>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      @TobiasM 您创建了一个非常好的联系表单,但是设置响应式需要付出很多努力..

      我在767px分辨率以下的一些元素中设置了不同的width

      下面是我的更改..

      首先我将box-sizing 设置为border-box

      *, ::after, ::before{
        box-sizing:border-box;
      }
      

      在那之后设置heightwidth 和其他需要 css 的移动和移动肖像来设置一切尽可能好..

      @media (max-width: 767px){
        #form-wrap:after {
          content: "";
          background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-after.png) no-repeat center;
          height: 158px;
          background-size: 100%;
        }
        form {
            position: relative;
            top: 300px;
            height: 138px;
            width: calc(100% - 20px);
        }
        #form-wrap:before {
            content: "";
            bottom: 76px;
            background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-before.png) no-repeat center;
            width: 100%;
            height: 194px;
            background-size: 100%;
        }
        #wrap {
          width: 320px;
        }
        #form-wrap:hover {
            height: 830px;
            top: -200px;
        }
        input[type="text"], textarea{
          width:100%;
          font-size: 12px;
        }
        #form-wrap input[type="submit"]{
          font-size:18px;
        }
        .turbotobias-contact-section-wrapper p {
            font-size: 18px;
        }
        label{
              font-size: 12px;
        }
      }
      @media (max-width: 330px){
            form{
              height: 128px;
            }
      }
      

      在这里,您可以在下面的小提琴中验证移动设备的响应性。

      body,
      div,
      h1,
      h2,
      form,
      fieldset,
      input,
      textarea,
      footer,
      p {
        margin: 0;
        padding: 0;
        border: 0;
        outline: none;
      }
      *, ::after, ::before{
        box-sizing:border-box;
      }
      .turbotobias-contact-section-wrapper {
        background-color: #ffffff;
        color: #000000;
        font-family: open sans, Arial, sans-serif;
        height: 60vh;
        display: flex;
      }
      
      .turbotobias-contact-section-wrapper p {
        font-size: 24px;
      }
      
      #wrap {
        width: 530px;
        margin: 20px auto 0;
        height: 1000px;
      }
      
      h1 {
        margin-bottom: 20px;
        text-align: center;
        font-size: 35px;
        font-family: open sans, Arial, sans-serif;
        color: white;
      }
      
      #form-wrap {
        overflow: hidden;
        height: 447px;
        position: relative;
        top: 0px;
        transition: all 1s ease-in-out 0.3s;
      }
      
      #form-wrap:before {
        content: "";
        position: absolute;
        bottom: 128px;
        left: 0px;
        background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-before.png) ;
        width: 100%;
        height: 317px;
      }
      
      #form-wrap:after {
        content: "";
        position: absolute;
        bottom: 0px;
        left: 0;
        background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-after.png);
        width: 100%;
        height: 259px;
        z-index: 999;
      }
      
      #form-wrap.hide:after,
      #form-wrap.hide:before {
        display: none;
      }
      
      #form-wrap:hover {
        height: 777px;
        top: -200px;
      }
      
      form {
        background: white;
        position: relative;
        top: 200px;
        overflow: hidden;
        height: 200px;
        width: 100%;
        margin: 0px auto !important;
        padding: 20px !important;
        border: 1px solid white;
        border-right: 3px;
        transition: all 1s ease-in-out 0.3s;
      }
      
      label {
        margin: 11px 20px 0 0;
        font-size: 15px;
        color: gray;
        text-transform: uppercase;
      }
      
      input[type="text"],
      textarea {
        font: 14px normal uppercase, arial, serif;
        color: dimgray;
        background: none;
        width: 380px;
        height: 37px;
        padding: 0px 10px;
        margin: 0 0 10px 0;
        border: 1px solid #f8f5f1;
        border-radius: 5px;
      }
      
      textarea {
        height: 80px;
        padding-top: 14px;
      }
      
      textarea:focus,
      input[type="text"]:focus {
        background: white;
      }
      
      #form-wrap input[type="submit"] {
        position: relative;
        font-family: open sans, Arial, sans-serif;
        font-size: 24px;
        color: gray;
        width: 100%;
        text-align: center;
        opacity: 0;
        background: none;
        cursor: pointer;
        border-radius: 3px;
        border: none !important;
        transition: opacity 0.7s ease-in-out 0s;
      }
      
      #form-wrap:hover input[type="submit"] {
        z-index: 1;
        opacity: 1;
        transition: opacity 0.5s ease-in-out 1.3s;
      }
      
      .turbotobias-contact-row {
        display: flex;
        width: 80%;
        max-width: 1080px;
        margin: auto;
        padding-bottom: 50px;
        flex-direction: row;
        flex-wrap: wrap;
      }
      #form-wrap:hover form {
          height: 515px;
      }
      @media (max-width: 980px) {
        .turbotobias-contact-row {
          padding: 30px 0;
        }
      }
      @media (max-width: 767px){
        #form-wrap:after {
          content: "";
          background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-after.png) no-repeat center;
          height: 158px;
          background-size: 100%;
        }
        form {
            position: relative;
            top: 300px;
            height: 138px;
            width: calc(100% - 20px);
        }
        #form-wrap:before {
            content: "";
            bottom: 76px;
            background: url(https://www.onlinefox.dk/wp-content/uploads/2019/09/brev-before.png) no-repeat center;
            width: 100%;
            height: 194px;
            background-size: 100%;
        }
        #wrap {
          width: 320px;
        }
        #form-wrap:hover {
            height: 830px;
            top: -200px;
        }
        input[type="text"], textarea{
          width:100%;
          font-size: 12px;
        }
        #form-wrap input[type="submit"]{
          font-size:18px;
        }
        .turbotobias-contact-section-wrapper p {
            font-size: 18px;
        }
        label{
              font-size: 12px;
        }
      }
      @media (max-width: 330px){
            form{
              height: 128px;
            }
      }
      <div class='turbotobias-contact-section-wrapper'>
              <div class='turbotobias-contact-row'>
                  <div id="wrap">
                      <br><br><br>
                      <div id="form-wrap">
                          <form>
                              <p>HEJ TURBOTOBIAS,</p>
                              <label for="email">Din besked:</label>
                              <textarea name="message" id="message" value="Your message"></textarea>
      
                              <p>VENLIG HILSEN,</p>
                              <label for="name">Navn:</label>
                              <input type="text" name="name" value="" id="">
      
                              <label for="email">Email:</label>
                              <input type="text" name="email" value="" id="email">
      
                              <input type="submit" name="submit" value="SEND MIN BESKED TAK!">
                              </form>
                              </div>
                  </div>
              </div>
          </div>

      【讨论】:

      • 媒体查询中不需要重复背景图片...330也不是标准媒体查询..还有很多代码重复
      猜你喜欢
      • 1970-01-01
      • 2013-08-15
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 2013-11-02
      相关资源
      最近更新 更多