FCC—Use the CSS Transform scale Property to Scale an Element on Hover_融糖_前端开发者

The transform property has a variety of functions that let you scale, move, rotate, skew, etc., your elements.

transform

When used with pseudo-classes such as :hover that specify a certain state of an element, the transform property can easily add interactivity to your elements.

:hovertransform

Here’s an example to scale the paragraph elements to 2.1 times their original size when a user hovers over them:

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

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

Note: Applying a transform to a div element will also affect any child elements contained in the div.

Note:div

 

练习题:

Add a css rule for the hover state of the div and use the transform property to scale the div element to 1.1 times its original size when a user hovers over it.

hoverdivtransformdiv

 

练习代码:

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

</style>

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

</style>

<div></div>


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

 

练习效果:

鼠标移动过去,放大1.1倍,挺好玩的

 

» 本文来自:前端开发者 » 《FCC—Use the CSS Transform scale Property to Scale an Element on Hover_融糖_前端开发者》
» 本文链接地址:https://www.rokub.com/73830.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!