Centering Buttons in HTML5 with CSS

54,964

Solution 1

Try putting the buttons inside a div with the style

text-align:center;
margin:auto;

Solution 2

Give specific width inside a div and then put margin:auto.

div
{
width://your width;
margin:auto;
}

Solution 3

this may work. Try,

margin : 0px auto;
Share:
54,964
dweeman
Author by

dweeman

Updated on July 09, 2022

Comments

  • dweeman
    dweeman almost 2 years

    I am wondering how I can center a group of social media buttons on my website.

    I previously used the <center> tags, but switched to HTML5, so i have the centering property for my other text and images in the css. However I have links to 4 different social media sites who all use different coding styles to implement the button. The follow is my code


    <-- FB --> <div class="fb-like" data-href="https://www.facebook.com/pages/La-Condesa/242967619184322" data-width="20" data-height="20" data-colorscheme="light" data-layout="standard" data-action="like" data-show-faces="false" data-send="false"></div>

    <-- Instagram --> <style>.ig-b- { display: inline-block; } .ig-b- img { visibility: hidden; } .ig-b-:hover { background-position: 0 -60px; } .ig-b-:active { background-position: 0 -120px; } .ig-b-32 { width: 32px; height: 32px; background: url(//badges.instagram.com/static/images/ig-badge-sprite-32.png) no-repeat 0 0; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {.ig-b-32 { background-image: url(//badges.instagram.com/static/images/[email protected]); background-size: 60px 178px; } }</style><br><br>

    <a href="http://instagram.com/lacondesafitzroy?ref=badge" class="ig-b- ig-b-32">img src="//badges.instagram.com/static/images/ig-badge-32.png" alt="Instagram" /></a>

    <-- Twitter --> <a href="https://twitter.com/LaaCondesa" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @LaaCondesa</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

    <-- Tumblr --><iframe class="btn" frameborder="0" border="0" scrolling="no" allowtransparency="true" height="25" width="114" src="http://platform.tumblr.com/v1/follow_button.html?button_type=2&tumblelog=LaaCondesa&color_scheme=light"></iframe>


    Is there a concise way of centering all of these items in HTML5? Or will I have to do it seperately for each? If that's the case, how can I center these items?

    Thanks

    EDIT: Sorry I left out, they are all contained within a container with the following properties .container { position: static;
    height: 700px; width: 780px; top: 50%; left: 50%; margin: 10px;
    margin-left: auto; margin-right: auto; }

    Check out www.lacondesa.com.au/test.html to see

  • dweeman
    dweeman over 10 years
    Worked perfectly! Thanks a lot
  • smartmouse
    smartmouse about 9 years
    Does margin:auto; really need?
  • Dan Goodspeed
    Dan Goodspeed about 9 years
    The margin:auto line centers the div.