让div在悬停后保持原位

时间:2017-03-01 18:52:09

标签: html css css3 animation

我试图让鼠标标记在悬停图像后保持原位。截至目前,当我悬停图像时,div向右移动。我尝试使用固定位置和绝对,但没有运气。这是HTML代码:

<div>
<button class="buttonTest"></button>
</div>

在CSS中:

.buttonTest{
    background-image:  url('http://hd-wall-papers.com/images/wallpapers/random-       image/random-image-16.jpg');
    width:150px;
    height:150px;

}

div {
  border-style: solid;
  height:auto;
  width:150px;
}

div{
  transition: all .2s ease-in-out;
}

div:hover{
  border-width:75px;
  transform: scale(.5);
}

在codepen中:https://codepen.io/dxs6040/pen/gmPgzz/

1 个答案:

答案 0 :(得分:0)

使用box-sizing:border-box和一些更改。这是理想的行为吗?

.buttonTest{
background-image:  url('http://hd-wall-papers.com/images/wallpapers/random-image/random-image-16.jpg');
  width:100%;
  height:100%;

}


div {
  border-style: solid;
  height:150px;
  width:150px;
  transition: all .2s ease-in-out;
  box-sizing: border-box;
}

div:hover{
  border-width:15px;
  transform: scale(.80);
}
<div>
<button class="buttonTest"></button>
</div>
<div>
<button class="buttonTest"></button>
</div>