Note: Nilesh's weblog is accessible to all versions of every browser. However, this browser may not support basic Web standards, preventing the display of our site's design details. We support the mission of the Web Standards Project in the campaign encouraging Internet users to upgrade their browsers. (Read More)

Nilesh's Weblog


Super Ragged Floats 2

December 16, 2002 09:28 AM


Super Super BikeLooks like I am obsessed with ragged floats. Yes, absolutely. Why wouldn't browsers have a simpler way of wrapping text around images? More research on ragged floats lead to this spanking new approach to wrapping around irregular outlines. This one uses pure divs and no backgrounds. Plain simple images and plain simple divs. Read More »

You really need to read Super Ragged Floats version1 to understand all this. Lets get down to the actual work directly. Experimenting with backgrounds, I found them a bit uncomfortable to work with. Plus, when a background image is being downloaded, there is no indication to the user. He assumes the page has loaded completely and goes on with his work. So I thought, let's put the image back on the page. So how do we wrap text around it. Use margins!

I used the following id definition for the div:

#toycycle{
    margin: -395px 0 0 0;
    padding: 0 0 0 0;
    height: 400px;
}

This tells the browser to push the div toycycle 400 pixels (the height of the image) above its default position on the page. The height: 400px rule avoids hiding the image behind text if the text is too less. We are going to place the image before this div so that the div starts from the image itself. For wrapping text, instead of using transparent spacer gifs, which are hated by most designers nowadays, we again use divs with this class:

.flowing {
    clear: left;
    float: left;
    margin: 0 2em 0 0;
    height: 15px;
}

The float:left attribute allows the div to stick to left side and the clear:left attribute clears up any text on the left side of the div. You can increase or decrease the space between divs and text by changing the margin attribute. Now, you use the id and class in this way:

Some text goes here...
<img src="toycycle.jpg" width="350" height="395" />
<div id="toycycle">
  <div class="flowing" style="width: 150px;"></div>
  <div class="flowing" style="width: 140px;"></div>
  <div class="flowing" style="width: 140px;"></div>
  <div class="flowing" style="width: 130px;"></div>
  <div class="flowing" style="width: 130px;"></div>
  ...
  <div class="flowing" style="width: 250px;"></div>
  <div class="flowing" style="width: 250px; 
     height: 8px;"></div>
... More text ... comes here.
</div>

Place the transparent images before the text and place them only as much required. For example, assuming the background image has a height of 400pixels, if you take each image 20pixels high, you'll need about 20 transparent images stacked up to cover up the whole image. Adjust the width of each image accordingly. You can experiment with this to achieve smooth text flow over the image. Like the last line of the divs. I have changed the height of the last image for more tighter layout. See a live example on my About page.

An Example:

Cras eget nulla id mi venenatis tincidunt. Nam lacus enim, fermentum non, rutrum sit amet, sodales ac, augue. Vivamus vel lacus eu erat vehicula dictum. Maecenas pulvinar nunc sed dui.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Vestibulum porttitor gravida lacus. Nunc nec lorem. Ut auctor pulvinar urna. Cras porttitor malesuada ligula. Morbi a magna. Aliquam erat volutpat. Donec placerat, pede sed gravida congue, urna pede pulvinar lacus, vitae pharetra neque odio a ante. Proin facilisis. Quisque ac pede ut nunc imperdiet porttitor. Fusce semper iaculis odio. Quisque laoreet pharetra justo. Aenean urna mi, porttitor id, eleifend at, fringilla sit amet, purus. Aliquam ullamcorper hendrerit mi. Praesent eleifend laoreet velit. Duis odio diam, placerat vel, vestibulum pharetra, molestie commodo, erat.Curabitur tincidunt, dolor blandit vulputate tincidunt, nisl augue feugiat massa, id condimentum dolor augue at quam. Integer nec sem. Nunc luctus. Cras nec dolor. Fusce tellus. Mauris adipiscing elit eget libero. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum id justo vel enim commodo iaculis. Nunc eget odio at justo sollicitudin facilisis. Integer justo sem, dictum sed, bibendum at, suscipit nec, tellus. Duis in magna non orci lacinia facilisis. Vestibulum ullamcorper ante ut arcu.




Comments

1 comment has been added. Add your comments.

1. Reference from kadyellebee
I had a nice time reading two tutorials by a plugin author's (he wrote the Blogtimes plugin) site at Nilesh.org.
Read more in ragged floats »
on Dec 21, 02:39 AM | link to this comment


Your Comments
* Please do not put off-topic comments. We reserve right to delete them at our discretion. You can post anonymously. If you are unable to see your posted comment immediately, it may have been queued for moderation. So do not submit it again. HTML formatting is allowed (only a, b, i, br, p, strong, em, ul, li & blockquote are allowed). Do not put paragraph tags. They are automatically inserted.

Name


Email


Homepage


Comments (required)


Remember Me??







© 2000-2003. Nilesh Chaudhari (mail AT nilesh.org)