Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add image to left of text via css

Tags:

css

How can I add an image to some text via css?

I've got this:

<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:

<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!

like image 214
Chris Conway Avatar asked Apr 09 '09 18:04

Chris Conway


People also ask

How do I put an image on the left side in CSS?

Float property in CSS will float an image to the left or right in the paragraph. The text in the paragraph will wrap around the image. Text-align property in CSS will position an image to the left, center or right of the page.

How do I put an image next to text in CSS?

Use the float CSS Property to Place the Text Next to an Image in HTML. We can use the float CSS property to define how an element can float. An element can float to the right or the left. Some other options are none which means the element will not float and, inherit which, will exhibit its parent's behavior.

How do I put text and images side by side in CSS?

In web design terms, this effect is known as floating the image. This is achieved with the CSS property float, which allows text to flow around the left-aligned image to its right side (or around a right-aligned image to its left side).

How do I put an image on the left side in HTML?

To align the image to the left use attribute value as “left”. Example : HTML.


1 Answers

.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 */ } 

Play around with padding and possibly margin until you get your desired result. You can also play with the position of the background image (*nod to Tom Wright) with "background-position" or doing a completely definition of "background" (link to w3).

like image 97
Jon Smock Avatar answered Oct 03 '22 18:10

Jon Smock