hover卡片向上移动6px

hover到卡片上的时候,卡片位移,向上移动6px:

1、现在原本布局就是卡片向上有个20的margin,所以hover的时候,直接改变margin-top值为14px,因为父元素的高度是用子元素撑开的,所以导致父元素的兄弟元素的位置也向上跑了,其实改起来很简单,既然向上减少了6,向下的margin加6就好了,保持总距离是20,就没问题。

2、用transform转换实现:transform: translateY(-6px), 如果有时间要求,配合transition过渡:transition: transform 0.2s;

原文地址:https://www.cnblogs.com/coconutGirl/p/10407518.html