How To Wrap Text Around Images Using CSS In Your Blog Posts?

In this article I want to show you how you can manually insert an advertisement into your post without having the need to find, install and configure a WordPress plugin. Many bloggers many come to a time when they want to promote a product, business or service on their blog in a post.

While there are WordPress plugins that can help with this on a more full time basis, many bloggers many only need to worry about inserting banners into their posts every so often. For whatever the reason may be, whether you would like to insert promotional banners into your posts manually on a full time basis or part time, this little trick might be something you enjoy.

In this tutorial, let’s use a Pepperjam graphic for an example. Below is the standard 300×250 Pepperjam graphic:

Rumors Are True

I was able to insert this banner into my post by copying and pasting the HTML code given to me from Pepperjam as shown below:

<a href=”http://www.gopjn.com/t/QjtAREY_O0dBPztBQ0M”><img src=”http://www.gopjn.com/b/QjtAREY_O0dBPztBQ0M” border=”0″ width=”300″ height=”250″ title=”Rumors Are True” alt=”Rumors Are True”></a>

Now this looks all fine and dandy, but to be honest it takes up a lot of vertical space on your blog post causing people to scroll down. Wouldn’t it be better to style this banner so that the content wraps around it? You can easily do this using some very basic CSS code. Here is an example of what your banner advertisement can look like it a post with just a few basic lines of CSS added:

This looks much better doesn’t it? Want the trick?

The above screen shot looks a lot better than the live version above. So the trick is very simple I am going to show you TWO ways that you can do this:

Method #1: Add CSS Code direct to the post:

Remember our HTML code that Pepperjam gave us? Here is the example of it below:

<a href=”http://www.gopjn.com/t/QjtAREY_O0dBPztBQ0M”><img src=”http://www.gopjn.com/b/QjtAREY_O0dBPztBQ0M” border=”0″ width=”300″ height=”250″ title=”Rumors Are True” alt=”Rumors Are True”></a>

Now remember, if we just add this code above without doing anything, the graphic will appear as shown LIVE at the very top of this post. We have to add some CSS code to this banner advertisement HTML code in order for the content of the post to wrap around it. Here is how we do that:

<div style=”float:left;padding-right:10px;”>
HTML CODE GOES HERE
</div>

That is all you need to do to wrap your post content around a banner. The complete example would look like this:

<div style=”float:left;padding-right:10px;”>
<a href=”http://www.gopjn.com/t/QjtAREY_O0dBPztBQ0M”><img src=”http://www.gopjn.com/b/QjtAREY_O0dBPztBQ0M” border=”0″ width=”300″ height=”250″ title=”Rumors Are True” alt=”Rumors Are True”></a>
</div>

Pretty simple, huh? I bet you didn’t realize how simple it was to make your banner advertisements look so good in your blog posts. As long as you know this very simple CSS trick, you will never need to worry about trying to find a WordPress plugin to do this, unless you are wanting more advanced management.

You can use the simple CSS trick even for images that you want to put into your posts as well. It doesn’t just have to be advertisements. Additionally, you can use the CSS trick to insert text into it and have your normal post content wrap around this extra text.

Method #2

The second method is really basically the same as the first method; however, it just makes life a little easier for you when you want to use the code in future posts.

Instead of having to worry about all this CSS mumbo jumbo in each post, wouldn’t it be easier to remember to use this instead:

<div id=”imagewrap”>
HTML CODE GOES HERE
</div>

That looks a lot nicer and even more simple! So how do we do that instead of method #1? Simple…

Open up your current WordPress Theme style.css file and add this these lines of code. You can add this code pretty much anywhere on the style.css file, perhaps so that you can remember where you put it just in case you want to remove it later, you should then put it on the very top of the file or the very bottom. Really though, it doesn’t matter.

Add this code into your style.css file:

#imagewrap {float:left;padding-right:10px;}

Be sure to make a back up copy of your style.css file before you go modifying it. After you add this simple line of CSS code into your style.css file, simply save the file and you’re done.

Now when you want to ad a promotional banner to your posts, things are even easier. Here is an example:

<div id=”imagewrap”>
<a href=”http://www.gopjn.com/t/QjtAREY_O0dBPztBQ0M”><img src=”http://www.gopjn.com/b/QjtAREY_O0dBPztBQ0M” border=”0″ width=”300″ height=”250″ title=”Rumors Are True” alt=”Rumors Are True”></a>
</div>

How Do I Float The Image To The Right?

Perhaps you do not like the image floating to the left and would like to have it float to the right. You can simply do this with this code:

<div style=”float:right;padding-left:10px;”>
HTML CODE GOES HERE
</div>

What Do These Codes Mean?

Let’s talk about that for a minute so that you understand what is going on here.

  1. float - this tells the image what direction to float or appear on a page. You can float an image to the left or the right.
  2. padding - this tell the image to have some extra space surrounding it. You can add extra padding to the top, right, bottom or left side of an image.
  3. div - div tags are enclosures that allow you to style HTML code within. Div  tags create an imaginary boundary around things such as an image, text or and common html elements. Div tags are the root to being able to style things the way you want using html and css.

That’s Cool… what other tricks to you have?

I know a lot about CSS and HTML here are a few more tricks that you might like or find useful to use with your blog posts.

Float Image Left with Right and Bottom Border:

<div style=”float:left;padding-right:10px;margin-right:10px;border-right:1px solid #A9A9A9;border-bottom:1px solid #A9A9A9;”>
HTML CODE GOES HERE
</div>

Ok, so let’s break this down:

  1. We have floated an image to the left. That means that text will wrap around the right side of it.
  2. We have added some space between the right side of the image so that the text doesn’t ride on it so closely. In this case I have added both extra margin as well as padding with a combined space of 20 pixels. You can add top, right, bottom and left margin space just as you can add padding. Experiment with the two and you’ll begin to see the difference between margin and padding.
  3. We have added a border to the right side as well as the bottom of this imaginary box. Again the imaginary box has been created by adding the <div> to </div> code. All the styling we do will be applied ONLY to the elements that are within these brackets.
  4. The border we have added to the right side and bottom is 1 pixel in width, it is solid and we have added the #A9A9A9 color to it.

Would you like for me to write more about HTML/CSS?

If you enjoyed this post and would like for me to write more about HTML/CSS drop me a comment and let me know. I know HTML/CSS like the back of my hand and will be happy to continue providing tutorials like this one. All yo have to do is drop me a comment and let me know.

Did you enjoy reading this post? I want to invite you to subscribe to my blog so that you won't miss my next article. Subscribing to my blog is totaly free. Simply, enter your email address in subscription box below and immediately you will start to receive copies of my articles sent to you by email. Your email address is never shared and you can unsubscribe anytime.

Enter your email address:

RSS feed| Trackback URI

34 Comments»

Christine Wrote a Comment: Subscribed to comments via email

Date/Time: 7-11-2008 01:08:34 Comment #16828

OMG, that is so awesome. I’ve tried so hard to figure out CSS, but it totally stumps me. However, the above was easy even for me to understand. I can do HTML, no problem. But when it comes to CSS, I suck.

I’d love to see more tutorials about CSS, just like you did above. It’s in plain English, that I can understand. I don’t have to have a physics degree to understand the wording, and that’s very important for me.

Very cool, I gotta give this one a try.

Thanks Garry.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 01:14:40 Comment #16829

You are very welcome… posts like this come very easy to me, so if you guys and gals like them, I can do a few more from time to time. ;)

 
 
Murray Wrote a Comment:

Date/Time: 7-11-2008 02:29:33 Comment #16831

Thanks Garry for the tips. Nice and simple and well demonstrated.

If you get the time, anymore CSS tips like this would be greatly appreciated.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:20:27 Comment #16870

No problem… I think I have a few more articles in the old writing tank. I am glad that this helped you. :)

 
 
Paul Wrote a Comment:

Date/Time: 7-11-2008 04:59:49 Comment #16834

I never really know this until now.

Nice of you for sharing it!

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:19:51 Comment #16869

You are very welcome. I am glad that it helped you. :)

 
 
JK Swopes Wrote a Comment:

Date/Time: 7-11-2008 06:09:28 Comment #16837

Crap dude! That was great! I will be bookmarking this for sure…for future reference.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:19:21 Comment #16867

Thanks man… I am glad that you found this to be useful. ;)

 
 
Stelian Andrei Wrote a Comment: Subscribed to comments via email

Date/Time: 7-11-2008 07:12:11 Comment #16842

Hi Garry!
First of all, very nice and useful tips. Just one small correction though: instead on div id=”imagewrap” I would recomend using div class=”imagewrap” and then style them in the CSS file like div.imagewrap

This is because the ID property of HTML elements needs to be unique, otherwise it will not validate according to W3C standards. It can happen to have more of these wrappers on the page when you display more posts at once, like in the case of the front page. Or even in the content of the same post.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:13:30 Comment #16866

I don’t worry one bit about whether my sites validate. It’s near impossible to make a site validate unless is it very very very simple. Even your blog has over 440 errors on it.

Here is a rather lengthy discussion on whether publishers should make sure their sites validate or not.

If validation had any influence over SEO, then I might be more concerned. Thanks for the comment though.

 
 
goldcoaster Wrote a Comment:

Date/Time: 7-11-2008 08:03:17 Comment #16844

great stuff Garry. This should work for blogger as well.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:11:12 Comment #16865

Yes… You can use CSS in blogger, self-hosted WordPress, WordPress.com or any kind of HTML page.

 
 
Mark Mason Wrote a Comment: Subscribed to comments via email

Date/Time: 7-11-2008 08:41:45 Comment #16845

Garry;

You forgot the easiest way to do CSS.

Hire Garry Conn

Seriously — nice tips.

Thanks
Mark

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:10:39 Comment #16864

Thanks Mark!

Wondering when I am going to be out of a job! LOL!!! I am glad you are lazy on learning CSS. :)

You have supplied my vehicle with many tanks of gas. ;)

 
 
Charlie Wrote a Comment:

Date/Time: 7-11-2008 10:31:52 Comment #16848

Dude, very cool, I had actually figured this out a little while ago after messing around with tags, which is the long way of doing this just because you end up putting more tags in, since you have to include the and tags as well to place a picture on your post. This is definitely quicker. CSS makes your life easier.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:09:39 Comment #16863

Here are some books that I own that you might be interested in:

http://www.garryconn.com/how-does-css-and-html-work-in-wordpress.php

 
 
David Cooley Wrote a Comment: Subscribed to comments via email

Date/Time: 7-11-2008 12:12:05 Comment #16850

Garry, good stuff to share. I would agree with Stelian on the Classes. I would also suggest coding all the margins and paddings at one time, instead of one at a time.

Example:

Instead of padding-left:10px (this only pads left side, all other sides are 0)

Use padding: 0px 0px 10px 10px; (this would pad bottom and left only)

This way you can control the sides a lot better. Usually whatever side you are placing the ad, there is no need to pad the outside edge.

Just remember whenever you do this with any CSS it works clockwise, starting at the top.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 18:08:37 Comment #16862

Well, let’s take things in small doses. I don’t want to complicate things. But you are right. You can look in a common stylesheet and see things like this:

#midpage-menu {
background: #EEEEEE;
padding: 10px 0 10px 10px;
border: 1px solid #333;
}

and the standard of the four numbers are always the same: Top, Right, Bottom, Left.

I may cover more posts on CSS if people would like to have them. Also, just like with common math 5+5 = 10 as well as 2+8 = 10. So with styling and even programming as you know there are many ways to achieve the same results.

 
 
Annie Binns Wrote a Comment:

Date/Time: 7-11-2008 15:50:20 Comment #16855

PLEASE more posts about HTML/CSS. This stuff has been making my hair hurt since I started the blog. My Google Analytics account shows 100 hits a day and that’s just me making a change, then going to see what it does — and repeating 99 times until something works. When I ran a W3C Validator tool it told me to back away from the keyboard.

Garry Conn Wrote a Comment:

Date/Time: 7-11-2008 17:54:30 Comment #16861

Annie don’t worry so much about making sure your blog will validate. So many people focus on making sure their blog or web site validates that it drives them nuts. It is about near impossible to make a blog or web site validate.

Seriously, making sure your site validates isn’t all that important at all. Google and other search engines recognize that many of us are just regular every day people who want to have web sites and blogs. Google and other search engines understand that we are NOT programmers or web designers.

If Google or other search engines took into consideration whether sites validated, then their index and database would be completely empty.

I do not believe that having a site that validates has any influence on SEO. But then again, what do I know, I am just a guy that pulls off $2500 dollar days off of free organic search traffic during the holidays. ;)

My advice to you is to continue doing what you are doing and perform many many tests on what you do. Look for ways to improve, but if improvements aren’t made, go back to what you were doing prior to running the test. This business is nothing more than a million “trials and errors”.

 
 
Top CD Rates Blog Wrote a Comment: Subscribed to comments via email

Date/Time: 7-11-2008 20:18:18 Comment #16872

Garry, nice post. I actually know CSS/HTML pretty well, but certainly a great service and money saver for those that don’t.

I do agree in keeping it simple and undertandable, such as using padding-left instead of padding 0 0 0 10 or whatever. I usually leave a comment at the top of my blog to help me remember the order.

I also agree that if W3C suggests using classes over id when something occurs multiple times on the page, it would be good to use the “correct” method. If people venture futher into Javascript, AJAX, etc. the id can become crucial.

Anyway, great, great job.

 
Wayne Wrote a Comment:

Date/Time: 7-12-2008 01:31:25 Comment #16887

Nice stuff. Nice to find someone giving out the tips in an easy to read manner!

I actually try my best to make my site validate, and I did it finally. But I confess, I started with a well validated blog system to begin with. But from there, all the changes I made had to conform as well. It just “feels” good. So i can relate to Annie to some degree, but it is more a feel good type thing.

Garry Conn Wrote a Comment:

Date/Time: 7-12-2008 01:35:51 Comment #16888

Wayne,

I can only imagine what your house looks like. You must put all your black socks in one drawer and your whites in another. You have a pair of hand cutters where you preciously clip each blade of grass in your yard…

You my friend. validate:
http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.waynejohn.com%2F&profile=css21&usermedium=all&warning=1&lang=en

Wow.. very nice work man. ;)

 
 
Bobby Revell Wrote a Comment: Subscribed to comments via email

Date/Time: 7-12-2008 14:57:17 Comment #16902

A few weeks ago, I tried a few methods you have form older posts. I tried the adsense script you wrote but it didn’t work on my particular blog. Then I tried the standard like you listed here, but the ad in single post, still didn’t wrap.

Finally I tried:

and it worked perfectly to wrap adsense in my single posts. Though I didn’t use the exact methods you had, you still pointed me in the right direction. I spent 6 hours on CSS tutorials and learned how to do it myself. Overall, this post along with other similar posts are probably the most complete of any blog. That’s what I like about your blog Garry, I always learn something new :smile:

 
Bobby Revell Wrote a Comment: Subscribed to comments via email

Date/Time: 7-12-2008 14:58:46 Comment #16903

Man…my comment didn’t show up correctly! I probably needed to remove the <’s

Garry Conn Wrote a Comment:

Date/Time: 7-12-2008 15:02:21 Comment #16906

I think that you need to use the <code> tags

<code>
Insert your code into the comment.
</code>

 
 
Bobby Revell Wrote a Comment: Subscribed to comments via email

Date/Time: 7-12-2008 15:19:23 Comment #16907

I could’ve had a V-8 :oops:

The code I used was:

 
Amit Wrote a Comment:

Date/Time: 7-19-2008 12:50:07 Comment #17066

Hi Gary,

I’m working on my own website and I’m trying to implement the wrap around picture code. Actually, what I’m really trying to wrap around is Google Adsense. Everything works fine, I’m using dreamweaver CS3 and I used your advice regarding the float left. That works. But what doesn’t is when I write the title of the blog, it also shows up on the right of the Adsense. I want the title to show up above the Google Adsense (treat this as a picture or its own separate Div). How can this be accomplished?

Additionally, what can I write in the code to make sure that every time I write in dreamweaver, it doesn’t double space everything?

Thanks so much,
Amit

Garry Conn Wrote a Comment:

Date/Time: 7-19-2008 13:46:37 Comment #17070

Amit,

Put the code directly below your <h2> tag.

Example:

<h2>This is the heading for my web page</h2>
<div style=”float:left;padding-right:10px;”>
GOOGLE ADSENSE CODE GOES HERE
</div>
<p>This is the first paragraph of your web page directly below the heading and also the content floats to the right of the Google AdSense code.</p>

In an email you asked me about removing the spacing between lines in paragraphs. Depending on what your problem is, I am not sure; however, you can experiment with the following:

p {
margin-top:0px;
margin-bottom:0px;
}

Another thing you could might be line height:

p {
line-height: 0px;
}

I think line height is one? I am not a CSS GURU by far, I just know what I need to know to make WordPress themes look awesome. ;)

 
 

Date/Time: 7-20-2008 06:15:24 Comment #17105

Hey G hows it going !!
Great tute, espcially the last comment, I was curious about that , good thing somebody asked it.
Have you seen http://www.csstextwrap.com/ its a beta site right now, basically it allows you to create your image wrap online and then copy and paste the code into your blog.
Thought it might be helpful.
Cheers and Beers
Shane

 
Mark Watrous Wrote a Comment:

Date/Time: 11-5-2008 19:58:12 Comment #25912

Hi Garry,

Thanks for explaining “float”. I guess I am trying to learn it without actually doing it, and btw, that does not work very well. Please feel free to add whatever strikes your fancy. I would make a members site, and charge for it. That way, you could offer up Wordpress, and CSS help for a nominal fee.

Mark

 
Von Glitschka Wrote a Comment: Subscribed to comments via email

Date/Time: 12-20-2008 04:34:01 Comment #28247

OK, not sure what I am doing wrong but I can’t get my image to wrap? Here is the code? I am using this in a Blogger post and I host my own images. The text above and below doesn’t wrap? Can you tell me what I messed up?

And I’ll be following you on Twitter now too. Thank you.

Von

Part of the post and code:

So most often you’ll find me doodling on simple white note pads that you can tear off and that is what I tend to prefer to draw on. I like the flexibility of being able to easily scan something in or tack it up for inspiration or put it in a project folder etc.

But if you’re looking for a top-notch bound sketch book look no further than the moleskin.

Like I said I prefer doodling on note pads and in the case of the image above I doodled that on a project outline. When I scanned it in I noticed it picked up some of the copy from the opposite side and I thought that looked pretty cool so I worked into the image.

Like “George” I have no idea as to the meaning of this but I sure do like it.

Remember, never stop drawing!

 
Von Glitschka Wrote a Comment: Subscribed to comments via email

Date/Time: 12-20-2008 18:22:53 Comment #28282

Well it only took me most of the day but I figured how to get this wrapping an image to work in Blogger. Turns out none of the code above is needed. Google hides it and assumes the only ones who’ll want to use that feature are those using their image hosting because the option isn’t given to self hosted images without going through their wonky upload method. In other words it should be right their inside their formatting GUI for posting but isn’t.

So now you know.

 
Swathi Wrote a Comment:

Date/Time: 4-17-2009 08:10:28 Comment #33179

Hi,

I will have one image tag and a text area.
I need to show the image in the middle of the content. But I can’t split the content.
the content in the text area should wrap around the image.
“float:left” will show the image in the top left corner.
But, i need to show the image in the middle of the content.

Plz help…

thanks in advance..
Swathi

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post


How To Make Money Online Video Tutorials

Learn how to make money online by downloading and watching these online video tutorials created by Garry Conn.

Choosing Keywords Using Google AdWords Keyword Tool (Part One)Choosing Keywords Using Google AdWords Keyword Tool (Part Two)Understanding Keyword Density and Keyword TargetingHow To Increase Backlinks To Your Blog or Website