html - 表单 block 不会相互堆叠

标签 html css forms

<分区>

在我的表单中,我有 2 个输入按钮。每个都有 100% 的宽度,所以它们应该相互堆叠,但它们没有。它们的宽度为 50%。为什么?

HTML

<form>
 <div class="input">
    <input type="text" class="button" id="email" name="email" placeholder="YOUR EMAIL"/>
    <input type="submit" class="button" id="submit" value="SUBSCRIBE"/>
 </div>      
</form>

CSS

body {
  background-color: yellow;
}

form {
    max-width: 450px;
    margin: 17% auto; }
form .input {
    display: flex;
    align-items: center; }
form .input:focus {
    outline: none;
    outline: 2px solid #E86C8D;
    box-shadow: 0 0 2px #E86C8D; }
form .button {
    height: 44px;
    border: none;
    width: 100%; }
form #email {
    background: #FDFCFB;
    font-family: inherit;
    color: #737373;
    letter-spacing: 1px;
    text-indent: 5%;
    border-radius: 5px 0 0 5px; }
form #submit {
    height: 46px;
    background: #E86C8D;
    font-family: inherit;
    font-weight: bold;
    color: inherit;
    letter-spacing: 1px;
    border-radius: 0 5px 5px 0;
    cursor: pointer;
    transition: background 0.3s ease-in-out; }
form #submit:hover {
    background: #d45d7d; }

http://codepen.io/Shalahmander/pen/yMJmBZ?editors=1100

最佳答案

display: flex 默认对齐一行中的子元素。将 flex-direction: column 添加到您的 form .input 类中,使它们显示在一列中,即彼此堆叠。

body {
  background-color: yellow;
}

form {
    max-width: 450px;
    margin: 17% auto; 
}
form .input {
    display: flex;
    flex-direction: column;
    align-items: center; 
}
form .input:focus {
    outline: none;
    outline: 2px solid #E86C8D;
    box-shadow: 0 0 2px #E86C8D; 
}
form .button {
    height: 44px;
    border: none;
    width: 100%; 
}
form #email {
    background: #FDFCFB;
    font-family: inherit;
    color: #737373;
    letter-spacing: 1px;
    text-indent: 5%;
    border-radius: 5px 0 0 5px; 
}
form #submit {
    height: 46px;
    background: #E86C8D;
    font-family: inherit;
    font-weight: bold;
    color: inherit;
    letter-spacing: 1px;
    border-radius: 0 5px 5px 0;
    cursor: pointer;
    transition: background 0.3s ease-in-out; 
}
form #submit:hover {
    background: #d45d7d; 
}
<form>
   <div class="input">
      <input type="text" class="button" id="email" name="email" placeholder="YOUR EMAIL"/>
      <br class="visible-xs">
      <input type="submit" class="button" id="submit" value="SUBSCRIBE"/>
   </div>
</form>

关于html - 表单 block 不会相互堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615310/

相关文章:

javascript - 我正在尝试为小屏幕提供响应式导航栏,如何将左侧链接更改为 css 下拉菜单?

javascript - 如何使用 HTML、CSS、Javascript 和有用的 JQuery 创建可点击 Div 的坐标网格?

Javascript:如何使用动态设置的 CSS 样式使在 Javascript 中创建的多个按钮居中

jquery - 悬停图像 - 在其上显示 div

html - 如何阻止div重叠三个较小的

php - 将 Symfony 表单单击按钮映射到数据类

css - 如何将 div 单元格设置为像 th?

javascript - 根据 URL 字符串和表单选择传递条件数据

html - 文本省略号不显示在 flexbox 元素上

html - 最小化窗口时背景最小化