I am a little confused over here. I have a txtbox and to the right of the txtbox, i want to insert a help icon. i have inserted that into a span. the problem is that i dont want to make this span a block because it goes down then. is there any other way to display this image without turning this into a block level element?
The Code goes here:
<input name="firm" type="text" id="firm" size="20" /><span id="helpico"></span>
The CSS:
#helpico{ background:url(images/question.png) left top; width:16px; height:16px;}
Usually span element is used to group inline elements together to implement style (using id or class attributes) or language information or JavaScript DOM(using id or class attributes), when no other element is found suitable to form that group. 3. The element can contain a piece of text or an image directly.
<span> is very much like a <div> element, but <div> is a block-level element whereas a <span> is an inline element.
Since span elements are rendered using display: inline by default, the two width CSS properties are ignored.
You can change the visual presentation of an element using the CSS display property. For example, by changing the value of display from "inline" to "block" , you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa.
You can use this CSS:
#firm
{
float: left;
}
#helpico
{
background:url(images/question.png) left top;
width:16px;
height:16px;
display: block;
float: left;
}
You have to use display block to enable widths and heights and to accept other styles. But to counter your issue of it "going down" you can set both the elements to float left and they will remain inline within the parent element.
Be aware that if the icon is relative to the content, it should be included with <img>
tag and an alt attribute.
After seeing that you don't want to use floats OR display block, there is only one way left, use display: inline-block;
.
Example for you here. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With