2

纯 CSS我想结合对齐的形式

<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>

分组输入

<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>

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

4

2 回答 2

2

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

.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>

于 2016-06-08T14:16:31.633 回答
1

您可以将 s 包装<label>在 div 中,并将该 div 放在<fieldset>. 像这样 :-

div.labels{
  display : inline-block;
  height : 100px;
}
div.labels div{
  display : flex;
  align-items : center;
  justify-content : right;
  height : 33.33%;
}
fieldset.pure-group{
  height : 100px;
  display : inline-block;
}
fieldset.pure-group input{
  height : 33.33%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form">
  <div class="labels">
    <div>
      <label>Name</label>
    </div>
    <div>
      <label>Password</label>
    </div>
    <div>
      <label>Email</label>
    </div>
  </div>
  <fieldset class="pure-group">
    <input type="text" id="name" placeholder="Username">
    <input type="text" placeholder="Password">
    <input type="email" placeholder="Email">
  </fieldset>
</form>

于 2016-06-08T14:14:40.980 回答