I can position a background image using the background property in an input field but I want an action to trigger when it is clicked.
Can I trigger an action on a background image click?
I just want to place a small ‘X’ image over the right hand side of input which clears the input.
You can absolutely position a link over the
<input>and then apply atext-indentto the<input>to make room for the image. For example:And:
Live demo: http://jsfiddle.net/ambiguous/TgaFf/
The outer
<div id="outer">is just there to give me something to applyposition: relativeto; absolutely positioned elements are positioned with respect to the nearest ancestor whosepositionis anything other thanstatic. Thetext-indenton the<input>starts the input cursor 16px from the left side of the<input>and thus leaves space for the image. In the real world you would, of course, adjust thetop,left, margins, paddings, … to make everything line up properly and look pretty.