[英]Vertically Aligning Input Elements
I'm having a bit of trouble with the following code. 我在使用以下代码时遇到麻烦。 I have an absolutely positioned div, inside of which I have 3 elements: 1 text input, 1 password and a button containing an image.
我有一个绝对定位的div,其中有3个元素:1个文本输入,1个密码和一个包含图像的按钮。 The markup is as follows:
标记如下:
<div id="credentials">
<input type="text" id="username" />
<input type="password" id="password" />
<button type="submit" id="login"><img src="./img/login.png" alt="Submit" /></button>
</div>
And the CSS: 和CSS:
div#credentials
{
position: absolute;
right: 5px;
top: 10px;
background-color: #494949;
}
#username
{
font-family: 'Lucida Sans', Arial, Helvetica, sans-serif;
font-size: 8pt;
color: #AAA;
padding: 3px;
margin: 0px;
}
#password
{
font-size: 8pt;
color: #AAA;
padding: 3px;
margin: 0px;
}
#login
{ background: transparent;
border: 0px;
padding: 3px;
cursor: pointer;
}
It looks as though the two first elements are situated at bottom of the div, and the button is situated at the top. 看起来前两个元素似乎位于div的底部,而按钮位于顶部。 I'd like to vertically align all 3 elements in the middle of the div, but after trying a number of different padding/margin combinations couldn't find anything that looks presentable across browsers.
我想在div的中间垂直对齐所有3个元素,但是在尝试了许多不同的填充/边距组合后,找不到在浏览器中可以显示的任何内容。 Does anyone have any experience with this issue?
有人对此问题有经验吗?
Try the vertical-align property 尝试垂直对齐属性
input, button {
vertical-align:middle;
}
Good vertical layout with display: list-item;
良好的垂直布局并
display: list-item;
at Align vertically input elements in div 在div中垂直对齐输入元素
No luck in Chrome/FireFox/Opera/Safari with vertical-align: …;
vertical-align: …;
Chrome / FireFox / Opera / Safari没有运气vertical-align: …;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.