Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align images horizontally CSS

Tags:

html

css

I want to align my three images horizontally instead of vertically what is the easiest way to achieve this? example

<div id="christmas_promotion_boxes">
            <div id="christmas_promo_1">
                <img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
            </div>
            <div id="christmas_promo_2">
            <img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
            </div>
            <div id="christmas_promo_3">
                <img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
            </div>
        </div>

#christmas_promotion_boxes {width:1000px; margin:0 auto 0 auto; text-align:center;}
like image 640
Karina Avatar asked Oct 30 '13 13:10

Karina


3 Answers

Display the divs as inline-block like so :

#christmas_promotion_boxes div {
  display: inline-block;
}

Fiddle

like image 61
Patsy Issa Avatar answered Sep 26 '22 03:09

Patsy Issa


You need the div's containing the images to be floated.

Add this section of code into your css:

#christmas_promotion_boxes > *{
    float:left;
}

http://jsfiddle.net/tDfCR/5/

like image 33
Joel Worsham Avatar answered Sep 27 '22 03:09

Joel Worsham


When I have inline elements I always put them in a ul and display the li's inline. This way you don't have to worry about floating anything and it is much more scalable.

<ul>
  <li id="christmas_promo_1"><img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100"></li>
  <li id="christmas_promo_2"><img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100"></li>
  <li id="christmas_promo_3><img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100"></li>
</ul>

ul{
 width:5em
}

li{
 display:inline;
 list-style-type:none;
}
like image 25
zazvorniki Avatar answered Sep 26 '22 03:09

zazvorniki