Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform a div without transforming icon inside

I am attempting to transform a div on hover using the CSS transform properties.

I have the transform doing what I want, but unfortunately its applying the transform (logically I guess), to the contents of the div I want to just apply the transform the div but not the underlying content (an Icon in this case).

I have seen a few methods on here, including applying the reverse transition to the icon, but when I did that it just multiplied the effect.

Here is my code:

.MsgBtnIcon {
  position: fixed;
  bottom: 0px;
  right: 7px;
  padding: 0px;
}
#transDemo2 div {
  display: block;
  position: fixed;
  bottom: 0px;
  right: 0px;
  background-color: #03A9F4;
  width: 75px;
  height: 75px;
  text-align: center;
  -webkit-transition: all 1s ease-in-out;
  -moz-transition: all 1s ease-in-out;
  -ms-transition: all 1s ease-in-out;
  transition: all 1s ease-in-out;
}
#transDemo2 div:hover,
#transDemo2 div.hover_effect {
  -webkit-transform: rotate(360deg) scale(2, 2) translateX(-19px) translateY(-19px);
  -moz-transform: rotate(360deg) scale(2, 2) translateX(-19px) translateY(-19px);
  -ms-transform: rotate(360deg) scale(2, 2) translateX(-19px) translateY(-19px);
  transform: rotate(360deg) scale(2, 2) translateX(-19px) translateY(-19px);
}
<script src="https://use.fontawesome.com/353bc64522.js"></script>
<div id="transDemo2">
  <div class="hover">
    <i class="fa fa-plus fa-4x MsgBtnIcon" aria-hidden="true"></i>
  </div>
</div>
like image 562
AntonZ Avatar asked Mar 03 '26 02:03

AntonZ


1 Answers

You can accomplish this by moving the MsgBtnIcon to be a child of the hover div and add pointer-events: none.

Updated fiddle example

.MsgBtnIcon {
  position: fixed;
  bottom: 0px;
  right:  7px;
  padding: 0px; 
  pointer-events: none;
}
#transDemo2 div {
  display: block;
  position: fixed;
  bottom: 0px;
  right: 0px; 
  background-color: #03A9F4;
  width: 75px;
  height: 75px;
  text-align:center;
  -webkit-transition: all 1s ease-in-out;
  -moz-transition: all 1s ease-in-out;
  -ms-transition: all 1s ease-in-out;
  transition: all 1s ease-in-out;

}

#transDemo2 div:hover, #transDemo2 div.hover_effect {
  -webkit-transform:rotate(360deg) scale(2,2) translateX(-19px) translateY(-19px);
  -moz-transform:rotate(360deg) scale(2,2) translateX(-19px) translateY(-19px);
  -ms-transform:rotate(360deg) scale(2,2) translateX(-19px) translateY(-19px);
  transform:rotate(360deg) scale(2,2) translateX(-19px) translateY(-19px);
}
<script src="https://use.fontawesome.com/353bc64522.js"></script>

<div id="transDemo2">
  <div class="hover"></div>
  <i class="fa fa-plus fa-4x MsgBtnIcon" aria-hidden="true"></i>
</div>
like image 164
Kevin Jantzer Avatar answered Mar 06 '26 02:03

Kevin Jantzer