1

can anyone help. I have an image of a butterfly that pops out a little when hovered over. I also have an image of a caterpillar. the trouble is that when the butterfly is hovered over the other image is also moving. how can i stop this?

The CSS is

/*Pink Butterfly - header*/
.pinkbutterfly  {
    width: 80px;
    height: 80px;   
    overflow: hidden;
    position: relative;
    top:-30px;
    left:230px;
    }

.hoverimg:hover{
    width: 95px;
    height: 95px;
    position: relative;
    top:-30px;
    left:220px;
    }

/*Blue/Yellow Caterpillar - header*/
.blueyellowcaterpillar{
    width: 140px;
    height: 80px;
    overflow: hidden;
    position: relative;
    top:30px;
    left:550px
    }

HTML:

<div id="headercontent"> 
  <img src="nurserylogo.png" alt="Cassiltoun Stables Nursery Logo" class="nurserylogo">
  <img src="Edited Characters/pinkbutterfly.png" alt="pinkbutterfly" class="pinkbutterfly hoverimg">
  <img src="Edited Characters/blueyellowcaterpillar.png" alt="blueyellowcaterpillar" class="blueyellowcaterpillar choverimg">
  <p style="font-family:'FeltTip'">Tel: 0141 631 5235</p>
  <div id="navigation">
    <ul class="navlist"> 
      <li> about </li>
      <li> pictures </li>
      <li> find us </li>
      <li> contact</li>
    </ul>
  </div>
</div>
4

1 回答 1

1

更改元素的大小会使布局重新排列。

要使其更大而不影响布局,请尝试

.hoverimg:hover {
    -webkit-transform: scale (1.2);
    transform: scale (1.2);
}

这应该使它更大,使其保持在先前位置的中心。如果这不是您想要的,请添加

    -webkit-transform-origin (top, center);
    transform-origin (top, center);
于 2013-06-12T18:31:09.947 回答