2

From Pure CSS I want to combine 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>

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

so that the inputs are stacked while still allowing horizontally aligned labels to be placed to the left. How can I achieve this effect?

Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153

2 Answers2

2

I came to a solution by applying the grouped input styling to a modified aligned form layout:

.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>
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
1

You can wrap the <label>s in a div and place that div on the left side of the <fieldset>. Like this :-

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>
Arjun
  • 1,261
  • 1
  • 11
  • 26