【问题标题】:CSS Contact Form not being responsiveCSS 联系表没有响应
【发布时间】:2019-02-20 14:04:48
【问题描述】:

我创建了一个联系表,一切看起来都不错,按照我想要的方式,但有问题。重新调整浏览器的大小/缩小浏览器时,表单没有响应。我搞砸了,我认为代码有点太多以至于我不知道我在做什么或已经做了什么。我快疯了!

当我重新调整浏览器的大小时,标签会超出它所在的容器。即使我尝试margin: 0 auto;,提交按钮也不居中

我将在下面发布 HTML 和 CSS 以及我的 CodePen。感谢您的帮助!

CodePen https://codepen.io/vCoCo/pen/MLReKK?editors=1100

HTML

<section id="contact">
  <div class="container">
    <form id="contactForm" action="contactform.php" method="post">
      <h2> Get In Touch! </h2>

      <div class="details">
        <label for="firstName"> First Name </label>
        <input type="text" id="firstName" name="firstName" placeholder="Enter First Name..." required>
      </div>

      <div class="details">
        <label for="lastName"> Last Name </label>
        <input type="text" id="lastName" name="lastName" placeholder="Enter Last Name..." required>
      </div>

      <div class="details">
        <label for="email"> Email </label>
        <input type="email" id="email" name="email" placeholder="Enter Email..." required>
      </div>

      <div class="details">
        <label for="textMessage"> Message </label>
        <textarea id="textMessage" name="textMessage" placeholder="Enter Message In Here..." required></textarea>
      </div>

      <input type="submit" value="Submit Message">

    </form>
  </div>
</section>

CSS

body{
  background-color: grey;
}
/**** GLOBAL ****/
.container{
  max-width: 80%;
  margin: auto;
  overflow: hidden;
  border: 2px solid white;
}

/********** CONTACT FORM **********/
#contact{
  max-width: 80%;
  margin: 100px auto;
  border: 1px dashed orange;
}

#contact .container{
  width: 500px;
  margin: 100px auto;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
}

#contactForm{
  margin: 0 auto;
}

#contactForm h2{
  text-align: center;
  margin-bottom: 10px;
}

.details{
  max-width: 500px;
  margin: 15px;
  padding: 10px;
  border: solid 1px #ff0000;
  overflow: hidden;

}

label{
  margin-bottom: 10px;
}

input[type=text], input[type=email]{
  width: 400px;
  padding: 12px 20px;
  margin: 8px 0;
  border: 2px solid;
  border-radius: 4px;
}

input[type=submit]{
  width: 200px;
  padding: 10px 20px;
  color: #fff;
  background-color: #000;
  border: 2px solid #fff;
  border-radius: 10px;
  font-family: inherit;
  cursor: pointer;
}

textarea{
  width: 300px;
  height: 200px;
  resize: none;
  font-size: 16px;
}

#contactForm textarea::placeholder{
  font-size: 16px;
}

【问题讨论】:

  • 你是否使用引导程序
  • 没有。不使用引导程序

标签: html css responsive-design


【解决方案1】:

你对几个元素的width 有问题,你设置了固定宽度,它会影响移动分辨率,还有容器溢出,它会使子元素隐藏在父元素中。

响应式模式的一个很好的解决方案是将宽度设置为父级的 100%,并设置最大宽度以获得更大的分辨率。

我为你的 Codepen 做了一个分支。

重要:大多数问题也是,确保设置全局元素的box-sizing。即* { box-sizing: border-box;}

希望这会有所帮助。

代码笔https://codepen.io/devlumberjack/pen/rPbMzr?editors=1100

【讨论】:

  • 谢谢!关于如何让“提交消息”按钮位于中心而不是位于左侧的任何想法?
  • 一个想法可能是将输入设置为 'Display: block;边距:0 自动;'应该可以完成这项工作。
  • 我不知道你可以为同一个元素添加最大宽度和宽度。对于#contact .container。您添加了 width: 100% 和 max-width: 500px;
  • 当然,它允许您设置宽度限制而不设置固定宽度。所以对于低于 500px 的屏幕,它将是 100%。这可能有助于理解:css-tricks.com/tale-width-max-width
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-30
  • 1970-01-01
  • 2020-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多