对齐文本框旁边的图像

时间:2013-05-04 17:29:25

标签: html css

我难以在文本框旁边对齐图像。我想知道除了设置填充和边距之外是否有一种简单的方法可以做到这一点。因为这些措施在每个浏览器中都有所不同我做了一个小提琴http://jsfiddle.net/wD5T9/

<div id='searchWrapper'>
<input id='searchBox' style='width:250px; border:1px solid #cccccc; border-radius:7px 7px 7px 7px; padding:5px 28px 5px 10px; margin-top:14px; margin-left:50px;height:18px;' type='text' placeholder='Search'/><img src='http://www.q-park.ie/Portals/8/images/search-icon.png'/>
</div>

2 个答案:

答案 0 :(得分:11)

只需添加到CSS:

#searchWrapper img {
    vertical-align: middle;
}

答案 1 :(得分:1)

每当我尝试非常精细地定位某些东西时,我选择使用这种方法:

position:relative;

然后我使用top, left, right and buttom.

进行定义

http://jsfiddle.net/wD5T9/5/

希望这有帮助