html - CSS 联系表没有响应

标签 html css responsive-design

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

当我调整浏览器大小时,标签超出了它所在的容器。提交按钮也没有居中,即使我尝试 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;
}

最佳答案

几个元素的 width 有问题,你设置的是固定宽度,这会影响移动分辨率,容器溢出也会让子元素隐藏在父元素中.

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

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

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

希望这对您有所帮助。

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

关于html - CSS 联系表没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54788223/

相关文章:

css - 网页在移动设备上没有响应

html - a/b 测试主要的 html/css 重新设计

html - css 不工作但样式 =""是

html - 如何在translateY后去掉div下面的空白

html - 挣扎于CSS网格

html - 仅使用 HTML 表格和 CSS 的锦标赛分组

html - 如何使图像缩小到正常 View ?

css - Font Awesome 图标不显示

css - 媒体查询 - 视口(viewport)的高度是否大于宽度?

javascript - 如何从打印页面更改 URL?