[英]How do I align label on top of an input form?
I am struggling with aligning my label with my forms. 我正在努力使自己的标签与表格保持一致。
This is how I want them: 这就是我想要他们的方式:
This is how I've coded it so far, and it's obviously not working. 到目前为止,这就是我编码的方式,并且显然不起作用。
<label for="email">Email address</label>
<input type="email" id="email" />
<label for="password_field">Password </label><span><a href="#">Forgot your password?</a></span>
<input type="password" id="password_field" />
<input type="submit" value="Sign in" id="sign_in_form" />
and this is the CSS: 这是CSS:
header input[type="email"], header input[type="password"], label {
display:block;
}
I am not sure how to align the labels, furthermore I have the link that is not part of the span that I want to keep next to it. 我不确定如何对齐标签,此外,我的链接不属于我要保留的跨度范围。 I'm lost.
我迷路了。
Could somebody help me? 有人可以帮我吗?
One way you could do it is to add a wrapping div with a class and adding a little CSS. 一种方法是添加带有类的包装div并添加一些CSS。
HTML: HTML:
<div class="inputWrapper">
<label for="email">Email address</label>
<input type="email" id="email" />
</div>
<div class="inputWrapper">
<label for="password_field">Password </label><span>
<input type="password" id="password_field" />
</div>
<input type="submit" value="Sign in" id="sign_in_form" />
<a href="#">Forgot your password?</a></span>
CSS: CSS:
.inputWrapper label{
display:block;
}
Here is a quick demo on codepen: http://codepen.io/miguel2k/full/lxopE 这是有关Codepen的快速演示: http ://codepen.io/miguel2k/full/lxopE
Here is one solution: http://jsfiddle.net/yLaxs/ 这是一种解决方案: http : //jsfiddle.net/yLaxs/
<label for="email">Email address
<input type="email" id="email" />
</label>
<label for="password_field">Password <a href="#">Forgot your password?</a>
<input type="password" id="password_field" />
</label>
<label>
<br />
<input type="submit" value="Sign in" id="sign_in_form" />
</label>
and the css 和CSS
label
{
float:left;
width:30%;
}
a
{
font-size:8px;
}
<label for="email">Email address <br/>
<input type="email" id="email" />
</label>
<label for="password_field">Password <a href="#">Forgot your password?</a>
<input type="password" id="password_field" />
</label>
<label>
<br />
<input type="submit" value="Sign in" id="sign_in_form" />
</label>
label
{
float:left;
width:30%;
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.