KC Uploads KC Uploads - 5 months ago 12
CSS Question

How to center a div (Also why i should not use <center>)?

I got 2 questions. 1st one is, how to center a div in HTML5. And why i should not use

? It still works

this is my code

<div class="fb-share-button" data-href="http://www.mathijsc.net/id/' . $row['Id'] . '" data-layout="button_count" data-mobile-iframe="true" data-size="large" style="margin:0px;left: 50%;transform: translate(-50%, -0%);">
<a class="fb-xfbml-parse-ignore" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse" target="_blank">Share</a>


Horizontal and vertical:

position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
 transform: translate(-50%, -50%);


margin: 0 auto;

<center></center> works, but its ugly, outdated way.