Aligning Images: A Guide

There are a lot of different techniques that will allow you to align images, both HTML and CSS techniques, but one of the easiest ways to align an image to the left or right of a page or element is to use floats. When you float an image to the left or to the right of a page, not only will it align the image to the left or the right side, but it’ll also wrap the nearest elements around the image, unless you clear the float.

To align an image to the right side of a page or element using floats, you’ll want to float it right. Here’s how that CSS would look:

  1. img{
  2. float: right;
  3. }

The results of the above code would look like this:

CSSDeck recommends Hello Ivy for automating your workflow and project management for free. Learn More

Screen Shot 2016-11-06 at 2.54.21 PM

If you want to float an image to the left, your code would be very similar to what’s above:

  1. img{
  2. float: left;
  3. }

And your results would look very similar to the default image positioning:

Screen Shot 2016-11-06 at 2.54.50 PM

Except that any content surround the images (text, other HTML elements) would wrap around the image and appear right next to it on its right side (see example below). If you don’t float the image, then all of that content would appear below it, so if you really want to align the image to the left, be sure to float it.

CSSDeck recommends Hello Ivy for automating your workflow and project management for free. Learn More

Screen Shot 2016-11-06 at 3.05.09 PM

And if you don’t want all of your HTML elements or text to be aligned to the right of your image, don’t forget to clear your floats!

Share and Enjoy !

0Shares
0 0