Search code examples
htmlcsstransformationscaling

CSS3 transform: scaling results in translation?


I have the following simple HTML code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <style>
      body {
        padding: 30px;
      }
      a {
        display: block;
      }
      a:hover {
        transform: scale(2); 
        transition: all 4s;
      }
    </style>
  </head>
  <body>

    <a href=#>Link</a>

  </body>
</html>

in which the Link is supposed to scale. However, it shifts to the left. What is the problem?


Solution

  • body {
      padding:30px;
    }
    a {
      display: inline-block;
      transition: all 4s;
    }
    a:hover {
      transform: scale(2); 
    }
    <a href=#>Link</a>

    You should have used display:inline-block to make it work. If it is what you are looking for, +1.