【问题标题】:Changing background-position-x on :hover在 :hover 上更改 background-position-x
【发布时间】:2018-12-05 00:29:48
【问题描述】:

我正在尝试通过在 x 轴上移动背景图像来获得一点悬停动画。但是,我似乎找不到如何捕获元素:悬停。有谁知道出了什么问题?下面的选择器有效吗?

感谢您的帮助

 div.card:hover .cardbg {

}

.card {
border-radius:15px;
border:none;
height: 280px;
position: relative;
background: linear-gradient(to bottom right,#ffec99 0,#ffb549 100%);
z-index: -1;
font-family: 'Arial';
}

.cardbg {
	width: 100%;
	height: 100%;
	background-image: url('images/atom-original.svg');
	opacity: 0.2;
	background-size: cover;
	background-repeat: no-repeat;
	background-position-x: 100px;
	transition: .2s ease all;
	position: absolute;
  top: 0;
  left: 0;
}

div.card:hover .cardbg {
background-position-x: 10px;
  background-color: red; 
}
<div class="card">
<div class="cardbg">
</div>

</div>

【问题讨论】:

    标签: css hover selection


    【解决方案1】:

    尝试从.card 类中删除z-index: -1。这对我有用。

    【讨论】:

    • @SaroVerhees 嘿,谢谢!如果您可以将答案标记为正确,那就太棒了!
    • 你明白了,伙计!
    猜你喜欢
    • 1970-01-01
    • 2012-03-28
    • 2012-03-07
    • 2021-10-17
    • 2015-11-26
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多