HTML/CSS - 无法从输入框中删除 'margin-top'

标签 html css forms

我似乎无法弄清楚,也许我遗漏了什么,但这是我的 HTML:

<style type="text/css"> 
    #loginForm {
        margin: 0;
        padding: 0;
        outline: 0;
    }
</style>

<input id="loginForm" type='text' height="30px" width="20px" /><img id='usernameIcon' src="shipping3.png" width="30px" alt="username" height="30px"/>

基本上,我希望输入框和图像彼此相邻。输入框和图像的高度相同。我希望它们直接并排放置,但由于某种原因,输入框有某种顶部边距,使其明显低于图像。这是为什么?

我在 Chrome 和 IE 10 上对此进行了测试,在这两个平台上,输入框都有某种顶部边距。我知道我可以将它们与 float 正确对齐,但难道不应该有另一种方法来从输入框中删除“margin-top”吗?

最佳答案

您应该将输入的 vertical-align 设置为顶部。

input { 
    vertical-align: top;   
    margin: 0;
}

jsFiddle

关于HTML/CSS - 无法从输入框中删除 'margin-top',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24873603/

相关文章:

html - 在 html/css 中滚动时如何使表头卡住/固定?

html - 仅使用 css 通过不同跨度为许多 div 切换显示隐藏/ block

javascript - 从二维距离数组在浏览器中绘制 map

javascript - 保持元素在父元素的底部

javascript - 我怎样才能打破表格的段落属性

css - 如何为 SharePoint 2007 topnav 中的单个单元格定义样式?

css - firefox 中的相对位置导致 google-map-markers 可点击区域出现问题

django - Django Admin 中的动态字段

javascript - 谷歌浏览器 ERR_CACHE_MISS 解决方法

php - 隐藏/返回发送按钮,单击时具有淡入淡出效果