One of the most important properties for web design is the Float property. The Float property is used to move elements to the right or left, so other elements can wrap around them. Many web designers use the Float property to wrap text around images without creating classes or IDs. When we use the Float property, elements that are continuous to the element will flow around it, depending on where the floated element was located at first and its Float value. Its markup values are: left, right, none, or inherit. Floated elements will move until they find a container. If your element has a size bigger than the next container, it will move downward until it finds room; so, keep in mind space and sizes. Also, make sure to specify the element’s width to avoid errors or miscalculations.
In this tutorial we will learn how to float an image to the left, so text will float around it without leaving white space around the image.
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
STEP ONE:
Let’s start by creating a basic HTML file with some content:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Use CSS Float Property to Wrap Text around an Image</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Use CSS Float Property to Wrap Text around an Image</h1> <p>One of the most important properties for web design is the Float Property. The Float Property is used to move elements to the right or left, so other elements can wrap around. Many web designers use the Float Property to wrap text around images without creating classes or IDs. When we use the Float Property, elements that are continuous to the element will flow around it depending on where the floated element was located at first and its Float value (right or left).Its markup values are: left, right, none, or inherit. Floated elements will move until they find a div container or another container. If your Floated element has a size bigger than the next container, it will move downward until it finds room; so, keep in mind space and sizes. Also, make sure to specify the element's width to avoid errors or miscalculations.<br /> In this tutorial we will learn how to float an image to the right, so text will float around it without leaving white space around the image. </p> <p>One of the most important properties for web design is the Float Property. The Float Property is used to move elements to the right or left, so other elements can wrap around. Many web designers use the Float Property to wrap text around images without creating classes or IDs. When we use the Float Property, elements that are continuous to the element will flow around it depending on where the floated element was located at first and its Float value (right or left).Its markup values are: left, right, none, or inherit. Floated elements will move until they find a div container or another container. If your Floated element has a size bigger than the next container, it will move downward until it finds room; so, keep in mind space and sizes. Also, make sure to specify the element's width to avoid errors or miscalculations.<br /> In this tutorial we will learn how to float an image to the right, so text will float around it without leaving white space around the image. </p> </body> </html>
STEP TWO:
Now, find any image that you want to include within the content. I chose the following image and I saved it for web inside a predestined images folder for my HTML page:
Image may be NSFW.
Clik here to view.
You can use your own image, or download my image at the end of this tutorial.
Place the image on the same line as text. I placed mine within the first paragraph tag:
<p><img src="images/Floatimage.jpg" width="100" height="78" alt="Floated Image" />One of the most important properties for web design is the Float Property. The Float Property is used to move elements to the right or left, so other elements can wrap around. Many web designers use the Float Property to wrap text around images without creating classes or IDs. When we use the Float Property, elements that are continuous to the element will flow around it depending on where the floated element was located at first and its Float value (right or left).Its markup values are: left, right, none, or inherit. Floated elements will move until they find a div container or another container. If your Floated element has a size bigger than the next container, it will move downward until it finds room; so, keep in mind space and sizes. Also, make sure to specify the element's width to avoid errors or miscalculations.<br /> In this tutorial we will learn how to float an image to the right, so text will float around it without leaving white space around the image. </p>
We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!
NOTE: Make sure to place elements that you plan to float before any element you wish to wrap around.
Preview in browser:
Image may be NSFW.
Clik here to view.
Notice that the HTML places our image as a container creating an unappealing white space around the image.
STEP THREE:
Luckily, we have a CSS property to fix the unpleasant open space around our image. Let’s Float our image to the left, so content can follow the element’s block and wrap around it.
Link a CSS file to your HTML and add the following declaration for your image:
Preview in browser:
Image may be NSFW.
Clik here to view.
Way better, huh?
STEP FOUR:
To create a little bit of space between our image and content let’s add a right margin to our image declaration:
p img { float: left; margin-right: 20px; }
Preview in browser:
Image may be NSFW.
Clik here to view.
Congratulations! You learned how to correctly place and float any element within your HTML page. Practice with more images and values to dominate CSS; as Publilius Syrus once said, “Practice is the best of all instructors”.
Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!