• Technosailor.com
  • Desk of the Editor
  • Entrepreneurship
  • Web Marketing
  • Tech Policy
  • Contenido Español
Technosailor
  • Authors
  • Twitter Pitch Me!
  • Disclosures
Feb
23
2006

Floating Images

Posted by: Aaron Brazell
Woodlawn, MD, USA

Blog Building BlocksA question that I get often and frustrates many non-technical bloggers is how to wrap text around images. There are two different ways to do this. They both work, but the second example is seen as “proper” and standards-based.

In our example, we have a content area that serves as the body of the website. It is in this area, we’ll experiment.

A few things to be aware of as we tackle this topic. The CSS property, float, works well when used well. According to the spec, “an element can be declared to be outside the normal flow of elements and is then formatted as a block-level element”. In other words, there are some potential unintended consequences. If your content is short and does not vertically scale to the size of the image, the floated element will not push other content (such as your next entry) farther down the page. Only elements deemed to be “in the normal flow of elements” will be able to push other elements down the page to prevent the floated image from overlapping with other page elements.

And the image we will use, a picture from a Dave Matthew’s concert I attended last year:

<img src="http://www.technosailor.com/images/dmb1.jpg"
    style="height:113px; width:150px;" alt="Dave Matthew's Show" />

Problem:
If I simply drop this image into my HTML, you’ll notice that the paragraph text around it will push above and below the image creating an awkward bit of white to the sides of it. Not really what we want. (Example)
example2-1.png

Solution 1
The first method for approaching this problem is through pure HTML. By using align="left" or align="right" in the image tag, the browser will render all the content around it. (example)
example2-2.png

Solution 2
The preferred method of doing this is through CSS. It employs adding CSS rules float:left; or float:right; to the image. Though I’ve appplied these inline with the <img> tag, this can also be moved to the <style type="text/css"> grouping in the page head or to its own CSS file. Also note how I’ve added margin-right:5px; to add a little padding around the image. (example)

Usage:
Inline:
<img src="http://www.technosailor.com/images/dmb1.jpg" 
style="height:113px; width:150px; float:left; margin-right:5px;" 
alt="Dave Matthew's Show" />

or CSS rule:

.floatimageleft {
float:left;
margin-right:5px;
}
<img src="http://www.technosailor.com/images/dmb1.jpg" 
   class="floatimageleft" style="height:113px; width:150px;" 
   alt="Dave Matthew's Show" />

example2-4.png

As a reference point, the images that I’m using to begin these entries is floated using the second method.

  • Add to Mixx!
  • Stumble it!
About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He served as Director of Technology at b5media from 2005-2008 and is currently an independent consultant.
Tagged: blog_building_blocks, Design, web_design at 12:23 pm -
discussion by DISQUS

Add New Comment

  • Subscribe:  This Thread
  • Go to:  My Comments ·  Community Page
  • Sort thread by:

    Viewing 1 Comment

    Thanks. Your comment is awaiting approval by a moderator.

    Do you already have an account? Log in and claim this comment.

      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Chelle 4 months ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      Thank you so much for writing this...it was driving me crazy not knowing how to make it work and couldn't find it anywhere on wordpress's docs or forums in a way i understood what they meant. my pictures are all nicely "floating" now.
      reply  edit  flag   record video comment
      http://itmightbelove.com /people/2d33bb3799b85ef503a36a54473d9f7f/
    discussion by DISQUS

    Add New Comment

    close Joe Chill(joechill)
    konvict

    status via twitter

    Murdering the Wayne parents, creating Batman · 2 minutes ago

    recent comments (follow comments)

      View Profile »
      Powered by Disqus · Learn more
      blog comments powered by Disqus
      Powered by Defender Hosting
      Freshbooks
      • Recent Posts

        • Issues don’t go away when Congress goes home…
        • C-SPAN Providing Social Media Hub for Conventions
        • Apples and Oranges, the Rise and Fall of Women Bloggers
        • Business Consulting Etiquette
        • Fantasy Football for Charity
      • Recent Comments

        Powered by Disqus
      • Tags

        Aaron Brazell Advertising Apple b5media Blogging book conferences Design entrepreneurship Facebook Finance and Funding Google guest_blogging holidays humor hurricanes_and_natural_disasters interesting job Links Marketing Music nfl Op-Ed Perfect Pitch personal politics pr Predictions productivity Programming Security Social Issues Social Media Social Networking social_issues Sports Tech Industry Technology Technosailor Travel twitter unix Venture Files WordPress you_can_blog

      • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy

        Twitter Pitch!

        <p>Twitter pitching is a form of pitch that requires succint "what does this mean for me" kind of pitching. It is the ultimate efficiency of words. You have 140 characters or less to tell me why your pitch matters to me or my readers. Please include a means of contacting you. This is included in your 140 characters. If you send successive pitches, you will likely be ignored, unless it's obvious that the first pitch was a case of "accidental send", etc.</p> <p>This form of pitching does not mean I'm being a diva. It means that my time is valuable, and you want a piece of it. It's good practice for you, and delivers your pitch in a format I want. Win-win.</p>


        (X) Close

        Twitter Pitch Me!