use the css transform scale property to scale an element on hover - zilongxuan001/LearnFreecode GitHub Wiki

使用CSS的transform scale的属性去改变hover上的元素比例

理解

transform属性有很多的功能可以让你的元素改变比例(scale),移动(move),旋转(rotate),扭曲(skew)等等。

当你使用伪类(pesedo-classes)比如用于显示元素一定状态的:hovertransform属性很容易为你的元素增加相互作用。

这是一个例子,当一个用户的鼠标停在段落上时,段落被变成原来的2.1倍。

p:hover {
   transform: scale(2.1);
}

练习

divhover状态增加一条CSS规则,使用transform属性。当用户把鼠标放在div元素上时,div会变成原来的1.1倍。

<style>
  div { 
    width: 70%;
    height: 100px;
    margin:  50px auto;
    background: linear-gradient(
      53deg,
      #ccfffc,
      #ffcccf
    );
  }
  
  div:hover {
    transform: scale(1.1);
  }
  
  
</style>

<div></div>

来源

Applied Visual Design: Use the CSS Transform scale Property to Scale an Element on Hover | Learn freeCodeCamp

CHANGELOG

2018-10-30 15:13:05

⚠️ **GitHub.com Fallback** ⚠️