0

I just updated this for clarity.

So I have some buttons I have created which consist of a circle and a font-awesome icon. Each of these buttons are to link to social media. I now want to put these buttons inside a table row, where each will be horizontally and vertically aligned to the center of each table cell. How do I horizontally align them?

Here is my html:

<!DOCTYPE html>
    <html lang="en">
    <head>
    <script src="https://use.fontawesome.com/604215ea7e.js"></script>
        <style>
         .social_icon
        {  
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #ccc;
            text-align: center;
            display: table-cell;
            vertical-align: middle;
        }
        .social_icon:hover
        {   
            background-color: #999;
            cursor: pointer;
        }
        #footer_social_icons
        {       
            width: 20%;
            height: 80px;
            background-color: #636363;
            text-align: center;
        }
        #footer_social_icons table
        {   
            width: 100%;
            height: 80px;
        }
        #footer_social_icons td
        {
            vertical-align: middle;
            border: 1px solid #fff; /* to show not centred */
        }
        </style>
    </head>
    <body>
    <div id="footer_social_icons">
        <table>
            <tr>
                <td>
                    <div class="social_icon">
                        <i class="fa fa-google-plus" aria-hidden="true"></i>
                    </div>
                </td>
                <td>
                    <div class="social_icon">
                        <i class="fa fa-facebook" aria-hidden="true"></i>
                    </div>
                </td>
                <td>
                    <div class="social_icon">
                        <i class="fa fa-twitter" aria-hidden="true"></i>
                    </div>
                </td>
                <td>
                    <div class="social_icon">
                        <i class="fa fa-envelope" aria-hidden="true"></i>
                    </div>
                </td>
            </tr>
        </table>
    </div>

    </body>
    </html>
Magearlik
  • 523
  • 1
  • 6
  • 18
  • Ugh using tables for layouting is bad practice. I think it's better if you used bootstrap, put divs inside a row div and that you dont worry about aligning – jelleB Jun 11 '16 at 09:36
  • i dont want to use bootstrap for like one css part. its kind of a waste. – Magearlik Jun 11 '16 at 10:34
  • Does this answer your question? [How to position a table at the center of div horizontally & vertically](https://stackoverflow.com/questions/7059394/how-to-position-a-table-at-the-center-of-div-horizontally-vertically) – miken32 Sep 03 '21 at 20:21

3 Answers3

0

Give margin auto for footer_social_icons id.

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
 .social_icon
{
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ccc;
    text-align: center;
    display: table-cell;
    vertical-align: middle;
}
.social_icon:hover
{
    background-color: #999;
    cursor: pointer;
}
#footer_social_icons
{    
    width: 20%;
    height: 80px;
 margin:0 auto;
    background-color: #636363;
    text-align: center;
}
#footer_social_icons table
{
    width: 100%;
    height: 80px;
}
#footer_social_icons td
{
    vertical-align: middle;
    border: 1px solid #fff;
}
  </style>
</head>
<body>
<div id="footer_social_icons">
    <table>
        <tr>
            <td>
                <div class="social_icon">
                    <i class="fa fa-google-plus" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-facebook" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-twitter" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                </div>
            </td>
        </tr>
    </table>
</div>
   
</body>
</html>
Mani
  • 2,675
  • 2
  • 20
  • 42
0
try below code..

do it in every tag And add below code in your css

<td>
   <div class="socicon">
       <div class="social_icon">
            <i class="fa fa-google-plus" aria-hidden="true"></i>
        </div>
    </div>
</td> 
.socicon {
    margin: 0 auto;
    text-align: center;
    width: 57%; // you have to adjust width as your requirement 
}
KHUSHBOO
  • 24
  • 4
0
Do you need like this


<!DOCTYPE html>
<html lang="en">
<head>
  <style>
 .social_icon
{  
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ccc;
    text-align: center;
    display: table-cell;
    vertical-align:center;
}
.social_icon:hover
{   
    background-color: #999;
    cursor: pointer;
}
#footer_social_icons
{    
    width:20%;
    height:80px;
    margin:auto ;
    background-color: #636363;
    text-align: center;
}
#footer_social_icons table
{   
    width: 100%;
    height: 80px;
}
#footer_social_icons td
{
    vertical-align: middle;
    border: 1px solid #fff;
}
  </style>
</head>
<body>
<div id="footer_social_icons">
    <table>
        <tr>
            <td>
                <div class="social_icon">
                    <i class="fa fa-google-plus" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-facebook" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-twitter" aria-hidden="true"></i>
                </div>
            </td>
            <td>
                <div class="social_icon">
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                </div>
            </td>
        </tr>
    </table>
</div>

</body>
</html>
SMS
  • 84
  • 5