html - 如何将分组输入与对齐表单结合起来?

标签 html css forms yui-pure-css

来自Pure CSS我要合并aligned forms :

<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form pure-form-aligned">
  <fieldset>
    <div class="pure-control-group">
      <label for="name">Username</label>
      <input id="name" type="text" placeholder="Username">
    </div>

    <div class="pure-control-group">
      <label for="password">Password</label>
      <input id="password" type="password" placeholder="Password">
    </div>

    <div class="pure-control-group">
      <label for="email">Email</label>
      <input id="email" type="email" placeholder="Email">
    </div>
  </fieldset>
</form>

grouped inputs :

<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form">
  <fieldset class="pure-group">
    <input type="text" placeholder="Username">
    <input type="text" placeholder="Password">
    <input type="email" placeholder="Email">
  </fieldset>
</form>

以便堆叠输入,同时仍然允许将水平对齐的标签放置在左侧。怎样才能达到这样的效果呢?

最佳答案

我通过将分组输入样式应用到修改后的对齐表单布局来找到解决方案:

.pure-form-aligned .pure-group .pure-control-group {
  margin: 0;
}
.pure-form.pure-form-aligned .pure-group .pure-control-group input {
  display: inline-block;
  position: relative;
  margin: 0 0 -1px;
  border-radius: 0;
  top: -1px;
}
.pure-form-aligned .pure-group .pure-control-group:first-child input {
  top: 1px;
  border-radius: 4px 4px 0 0;
  margin: 0;
}
.pure-form-aligned .pure-group .pure-control-group:last-child input {
  top: -2px;
  border-radius: 0 0 4px 4px;
  margin: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form pure-form-aligned">
  <fieldset class="pure-group">
    <div class="pure-control-group">
      <label for="name">Username</label>
      <input id="name" type="text" placeholder="Username">
    </div>

    <div class="pure-control-group">
      <label for="password">Password</label>
      <input id="password" type="password" placeholder="Password">
    </div>

    <div class="pure-control-group">
      <label for="email">Email</label>
      <input id="email" type="email" placeholder="Email">
    </div>
  </fieldset>
</form>

关于html - 如何将分组输入与对齐表单结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37704351/

相关文章:

forms - Play 如何为包含枚举的案例类实现隐式写入或格式

html - Word Wrap a Div,全部在一行上

jquery - 在移动设备上查看时,Bootstrap 菜单会完全显示。

html - 从浏览器底部取消附加页脚

CSS:这个星号 (*) 的作用是什么?

html - Flexbox 对齐许多元素

带有单选框和复选框的 JavaScript "Check All"

php - HTML 表单 PHP 发布到自己以验证或提交到新页面

javascript - 检查是否有多个具有相同值的输入字段

jquery - 移动全屏背景图片