Search code examples
cssalignment

Image alignment within a row of divs


I have a row of divs which I would like the images to centre vertical and horizontally.

<div id="treatments-wrapper">
                <div class="heading">
                    <h2>Our Treatments</h2>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
            </div><!--treatments-wrapper-->




 #treatments-wrapper {
    width:960px;
    height:100px;
    float: left;
    margin: 10px 0;
    border-bottom: #373839 solid 10px;
}

.treatments-logo {
    width: auto;
    height: 60px;
    float: left;
    margin: 0 8px;
}

.treatments-logo img {
    display: block;
    margin: auto;
}

.heading {
    width:960px;
    height: 40px;
    background-color: #373839;
    float: left;
    margin:
}

Here it is on jsfiddle

For this example I have used the same image 3 times, but it will be a row of different logos, all with different height and widths. Can anyone suggest something I could try out?


Solution

  • try display:table-cell; with vertical-align:middle;

    .treatments-logo {
        width: 1%;
        display:table-cell;
        height: 60px;
        vertical-align:middle;
    }