Transform CSS property doesn't work with <a> element

喜夏-厌秋 提交于 2019-11-29 09:16:34

transform is not applicable to inline elements such as <a>. You could display the link as inline-block or block to get transform to work:

transformable element

A transformable element is an element in one of these categories:

  • an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose display property computes to table-row, table-row-group, table-header-group, table-footer-group, table-cell, or table-caption [...]

Where atomic inline-level elements include:

replaced inline-level elements, inline-block elements, and inline-table elements

a { display: inline-block; }
a:hover { transform: scale(2,2); }

Besides, there's no on-click state available in CSS. Possible options are :active or :hover, or using checkbox hack.

a {
  background-color: green;
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border: 2px solid #85ADFF;
  border-radius: 30px 10px;
  transition: all 2s;
  display: inline-block; /* <-- added declaration */
}
a:hover{ transform: scale(2,2); }
/* just for demo */
body { padding: 2em; text-align: center; }
<a href="xyz.html">click here</a>

Use display:block and give it a height and width

a {
  background-color: green;
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border: 2px solid #85ADFF;
  border-radius: 30px 10px;
  transition: 2s all ease-in;
  display: block;
  width:100px;
  height:50px;
}
a:hover {
  transform: scale(2, 2);
}
<center><a href="xyz.html">click here</a>
</center>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!