WsMom
WsMom

Reputation: 51

I need images to align horizontally and be centered on the page

I am not sure how to align images horizontally and have them be centered on a page without using tables. I tried this with divs but cant get it to center on the page. I also want them to be responsive so they always stay in the middle when sized down.

This is as far as I got in JSFiddle: http://jsfiddle.net/DrSRT/403/

CSS

/*Black and White
--------------------------------------------------*/
.bw {
  -webkit-transition: all .5s ease;
  -moz-transition: all .5s ease;
  -o-transition: all .5s ease;
  -ms-transition: all .5s ease;
      transition: all .5s ease;
}

.bw:hover {
  -webkit-filter: grayscale(100%);
}


*/container
-----------------------------------------*/
.footersocial {
width:100%;
float:center;
}

HTML

<div id="footersocial"><div class="bw pic"><a href="https://www.facebook.com/PeopleAndPlatforms" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_facebook_hover.png" alt="facebook"></a></div>
<div class="bw pic"><a href="http://twitter.com/peoplenplatform" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_twitter_hover.png" alt="Twitter"></a></div>
<div class="bw pic"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_pinterest_hover.png" alt="pinterest"></div>
<div class="bw pic"><a href="http://www.linkedin.com/company/people-&-platforms" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_linkedin_hover.png"  alt="linkedin"></a></div>
<div class="bw pic"><a href="https://plus.google.com/u/1/112443165541377795854" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_gplus_hover.png"  alt="googleplus"></a></div>
</div>

Upvotes: 0

Views: 52

Answers (2)

Ignas Damunskis
Ignas Damunskis

Reputation: 1504

Here I made an example changing and adding some CSS:

http://jsfiddle.net/DrSRT/405/

Mostly I aligned .footersocial to center using margin: 0 auto;, but for that you need fixed width. Now to make it responsive, use @media screen and change .footersocial width once screen width is changed. Once is smaller the images gets smaller too, since their width is in %.

Example:

@media screen and (max-width: 720px) {
    .footersocial {
        width: 100px;
    }
}

Media query W3S documentation: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

Upvotes: 1

DRD
DRD

Reputation: 5813

Here's one solution using tables: http://jsfiddle.net/Lkynvdxp/.

HTML:

<div id="footersocial">
    <a href="#">
        <img src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_facebook_hover.png" />
    </a>
    <a href="#">
        <img src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_twitter_hover.png" />
    </a>
    <a href="#">
        <img src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_linkedin_hover.png" />
    </a>
    <a href = "#">
        <img src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_gplus_hover.png" />
    </a>
</div>

CSS:

#footersocial {
    display: table;
    margin: 0 auto;
}

#footersocial > a {
    display: inline-block;
    position: relative;
    width: 34px;
    height: 33px;
}

#footersocial > a > img {
    height: 100%;
}

#footersocial > a:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.5s linear;
} 

#footersocial > a:hover:before {
    opacity: 1;
}

Here's another solution using text-align: center: http://jsfiddle.net/k7ye3t0p/.

CSS:

#footersocial {
    text-align: center;
}

/*  The rest is the same as in the first solution */

Upvotes: 0

Related Questions