将 html 输入对齐在同一行
有人可以给出一个简单的解决方案,如何将表单输入对齐在同一行上, 例如,很多时候,当我构建表单时,我可以让它们彼此对齐,并且看起来不错,但是如果我将两个输入(如文本区域/文本)放在另一个文本或按钮旁边,我会得到垂直对齐差异。有没有办法解决这个问题而不需要摆弄边距和填充?
前任:
<style type='text/css'>
form{
display:inline;
}
textarea{
font-size:25px;
height:25px;
width:200px;
}
input.button{
height:25px;
width:50px;
}
</style>
<form>
<textarea >Value</textarea><input type='button' class='button' value='Go'>
</form>
Can somebody give a simple solution as to how to align form inputs on the same line,
for example, many times when I am building a form I can get them to align on top of each other and it looks sound, but if i put two inputs like a textarea/text next to another text or a button, I get vertical alignment differences. Is there a way to fix this without fiddling with the margins and padding?
ex:
<style type='text/css'>
form{
display:inline;
}
textarea{
font-size:25px;
height:25px;
width:200px;
}
input.button{
height:25px;
width:50px;
}
</style>
<form>
<textarea >Value</textarea><input type='button' class='button' value='Go'>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
你有没有尝试过使用vertical-align css属性?
这样一切都会看起来一致,并且您不必考虑利润。
Have you tried playing with the vertical-align css property?
That way everything will look consistent and you won't have to play with margins.
或者
根据您的垂直挑战方式进行选择
or
take your pick depending on which way your vertically challenged
添加
vertical-align
似乎对我有用:Adding a
vertical-align
seems to work for me:您通常可以使用
display:inline-block;
或float:left;
您希望项目在顶部或底部对齐吗?在您的示例中,您尚未关闭输入类型,它应该是
type='button'
- 您缺少一个 apos。You can usually use
display:inline-block;
orfloat:left;
Are you wanting items to be alighed at the top or bottom?In your example you haven't closed the input type, it should be
type='button'
- you're missing an apos.只需将
float:left
赋予文本区域http://jsfiddle.net/2qdJc/2 /
Just give
float:left
to the textareahttp://jsfiddle.net/2qdJc/2/
当然,这让 CSS 纯粹主义者感到不安,但这确实很容易......
Sure, it makes the CSS purists squirm, but it's certainly easy...
你可以做这样的事情(在我的例子中有效):
这是一个演示: http://jsfiddle.net/ gn3qx6w6/1/
You can do something like this ( worked in my case ):
Here is a demo: http://jsfiddle.net/gn3qx6w6/1/
对我来说,我使用了一个div并将所有输入放入div中并使用了vertical-align:top;对于div
For me i used a div and put all inputs in div and used vertical-align:top; for div