css - 在鼠标关闭事件上更改动画原点
问题描述
我有一些 css/html 代码。我想通过执行以下操作来改善我的“悬停”状态:当我将鼠标悬停在一个按钮上时,有一个 before 元素从左向右滑动。我可以很容易地从右到左改变它。但是,当我执行“悬停”操作时,在元素向相反方向滑动之前 - 从右到左。我想要实现的是将其宽度从 100% 设置为 0%,但从左到右。我应该怎么做才能得到结果?
https://codepen.io/trueFalse24/pen/YzKNgYm
a{
background: #7f8c8d;
padding: 20px 30px;
text-transform: uppercase;
color: #fff;
position: relative;
&:before{
content: '';
position: absolute;
top: 0;
left: 0;
width: 0%;
height: 100%;
background: rgba(236,240,241, 0.3);
transition: all 0.3s ease;
}
&:hover{
&:before{
width: 100%;
}
}
}
解决方案
left
我已经修改了您的笔,通过更改和属性的一些用法来获得效果right
。我的编辑在下面的评论中标记。
.container{
padding:0;
margin: 0;
box-sizing: border-box;
background: #3498db;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
a{
background: #7f8c8d;
padding: 20px 30px;
text-transform: uppercase;
color: #fff;
position: relative;
&:before{
content: '';
position: absolute;
top: 0;
right: 0; /* Replaced left */
width: 0%;
height: 100%;
background: rgba(236,240,241, 0.3);
transition: all 0.3s ease;
}
&:hover{
&:before{
width: 100%;
right: auto; /* Added */
left: 0; /* Added */
}
}
}
}
推荐阅读
- offset - OFFSET 行中最后一个非空白单元格
- php - 如果/否则无法正常工作。可能是什么问题呢?
- c - C结构未初始化的外部构造函数
- reactjs - 如何动态打开/关闭代码拆分
- java - List 不为空,但 poll 方法返回 null
- javascript - angular2-highchart 折线图在 y 轴上显示错误值
- php - PHP & XML:如何比较两个 XML 元素的文本内容?
- python - python中从1到n,2到n,... n的总和
- javascript - Axios 数据未定义
- node.js - 将 MongoDB 与本机驱动程序和 Express.js 一起使用时,“拓扑被破坏”