Equidistant Objects with CSS

/ Published in: CSS
Save to your folder(s)

Creating a horizontal row of objects that are equidistant from each other is another one of those things in web design that is much more difficult than it should be. This can be a very useful thing to do, especially in fluid width layouts when you are trying to make the most of whatever horizontal space you have. Here are the goals we are trying to achieve:

Copy this code and paste it in your HTML
  1. <!--PASS: First on the left, float the rest right in equal size boxes
  3. Fortunately the table idea sparked some thought. The first image needs to be left aligned, but all the rest of them could be right-aligned. In fact, if they are, and also inside of boxes that divide the rest of that space evenly, that might just do it. Perhaps this is best explained visually:
  5. floatytechnqiue.png
  6. -->
  8. HTML:
  10. <img src="images/shape-red.png">
  11. <div id="movers-row">
  12. <div><img src="images/shape-green.png"></div>
  13. <div><img src="images/shape-yellow.png"></div>
  14. <div><img src="images/shape-blue.png"></div>
  15. </div>
  17. CSS:
  19. #movers-row {
  20. margin: -120px 0 0 120px;
  21. }
  22. #movers-row div {
  23. width: 33.3%;
  24. float: left;
  25. }
  26. #movers-row div img {
  27. float: right;
  28. }

URL: http://css-tricks.com/equidistant-objects-with-css/

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.