Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put an icon and an input text on the same line?

Tags:

html

css

I want to put an icon on the left and an input type text on the right occupying all the remaining space.

----------------------------------------------------
| [ico]  ----------------------------------------  |
|        |   input type="text"                  |  |
|        ----------------------------------------  |
----------------------------------------------------

If I set both with display: inline-block and set the input's width to 100% it jumps the line, because 100% is not considering the space - icosize...

I want to expand the input to the remaining available space (I don't care for vertical align). Is there a way to achieve this behavior without using tables?

An example of the problem on jsFiddle.

like image 554
BrunoLM Avatar asked Nov 30 '10 12:11

BrunoLM


3 Answers

A bit less complicated that ianaré's version and works in IE6:

http://jsfiddle.net/sUYBS/23/

like image 105
RoToRa Avatar answered Nov 15 '22 05:11

RoToRa


Try this ...

<div style="display: table;">
<div style="display: table-row; width:100%;">
    <div style="display: table-cell;">
    <img src="img.png" width="16" height="11" alt="img"/>
    </div>
    <div style="display: table-cell; width:100%;">
    <input type="text" style="width:100%;"/>
    </div>
</div>
</div>
like image 26
ianaré Avatar answered Nov 15 '22 05:11

ianaré


float:left; for the icon. See, http://jsfiddle.net/sUYBS/11/

like image 32
Robin Maben Avatar answered Nov 15 '22 06:11

Robin Maben