如何将分组的输入与对齐的表格结合起来?
How to combine grouped inputs with aligned forms?
来自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>
<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>
以便堆叠输入,同时仍然允许将水平对齐的标签放置在左侧。我怎样才能达到这个效果?
您可以将 <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>
我通过将分组输入样式应用于修改后的对齐表单布局来找到解决方案:
.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>
来自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>
<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>
以便堆叠输入,同时仍然允许将水平对齐的标签放置在左侧。我怎样才能达到这个效果?
您可以将 <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>
我通过将分组输入样式应用于修改后的对齐表单布局来找到解决方案:
.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>