How to put image and input on the same line with css

淺唱寂寞╮ 提交于 2021-02-19 06:21:10

问题


I am trying to do something really simple: have image and input on the same line, but can not achieve it:

HTML

<img src="path/to/img"/>
<input/>

CSS

img {
    height: 50px;
}
input {
    height: 50px;
    margin: 0;
    padding: 0;
}

As you clearly see from this fiddle, image is much higher than the input. How can I fix it?


回答1:


Use the vertical-align property:

img{
    height: 50px;
    vertical-align: middle;
}

See updated fiddle




回答2:


I was able to achieve the effect you are looking for with floats:

img{
    height: 50px;
    float: left;
}
input{
    height: 50px;
    margin: 0;
    padding: 0;
    float: left;
}

Fiddle




回答3:


Use vertical-align, like this:

img{
    height: 50px;
    vertical-align: middle;
}
input{
    height: 50px;
}



回答4:


You can also set float on the img like this:

img{
    height: 50px;
    float:left;
}
input{
    height: 50px;
}


来源:https://stackoverflow.com/questions/24520295/how-to-put-image-and-input-on-the-same-line-with-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!