Xiraa - Tech Forum
Add image to left of text via css - Printable Version

+- Xiraa - Tech Forum (https://xiraa.com)
+-- Forum: Tech Forums (https://xiraa.com/forum-4.html)
+--- Forum: Programming (https://xiraa.com/forum-11.html)
+--- Thread: Add image to left of text via css (/thread-81.html)



Add image to left of text via css - Oso - 11-13-2023

How can I add an image to some text via css?
I've got this:
Code:
<span class="create">Create something</span>
and I want to add a 16x16 image to the left of that by using css. Is this possible or should i just manually add this image like so:
Code:
<span class="create"><img src="somewhere"/>Create something</span>
I'd rather not have to manually change all of the places which is why I wanted to do it via css.
thanks!


RE: Add image to left of text via css - Anurag M - 11-13-2023

Try Something like this:

Code:
.create{
background-image: url('somewhere.jpg');
background-repeat: no-repeat;
padding-left: 30px;  /* width of the image plus a little extra padding */
display: block;  /* may not need this, but I've found I do */
}

You might have to play around with padding and possibly margin until you get your desired result.