Home > Net >  CSS Transform reset - which is the correct approach?
CSS Transform reset - which is the correct approach?

Time:05-29

** all hover code is working . i m confuse which one is correct syntax for reseting transform . i did not find any blog article thats give me full detaiils of css transform how it computed behind the scene**

<style>
 .box{
   height: 100px;
   width : 100px;
   background-color:red;
   transform: translateX(10px) scale(2) rotate(45deg);
}
.box:hover{
  transform: none ;
}

or

.box:hover{
   transform: translateX(0) scale(0) rotate(0);
}

or

.box:hover{
   transform: translateX(0);
}
</style>

<div >
</div>

CodePudding user response:

As per the MDN documentation, the Initial value is none.

You can reset the transformation using:

div.someclass {
    transform: none;
}

Using vendor prefix:

div.someclass {
    -webkit-transform: none; /* Safari and Chrome */
       -moz-transform: none; /* Firefox */
        -ms-transform: none; /* IE 9 */
         -o-transform: none; /* Opera */
            transform: none;
}

The transform CSS property lets you rotate, scale, skew or translate an element. It modifies the coordinate space of the CSS visual formatting model.

If the property has a value different than none, a stacking context will be created. In that case, the element will act as a containing block for any position: fixed; or position: absolute; elements that it contains.

Syntax

/* Keyword values */
transform: none;

/* Function values */
transform: matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform: perspective(17px);
transform: rotate(0.5turn);
transform: rotate3d(1, 2.0, 3.0, 10deg);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: rotateZ(10deg);
transform: translate(12px, 50%);
transform: translate3d(12px, 50%, 3em);
transform: translateX(2em);
transform: translateY(3in);
transform: translateZ(2px);
transform: scale(2, 0.5);
transform: scale3d(2.5, 1.2, 0.3);
transform: scaleX(2);
transform: scaleY(0.5);
transform: scaleZ(0.3);
transform: skew(30deg, 20deg);
transform: skewX(30deg);
transform: skewY(1.07rad);

/* Multiple function values */
transform: translateX(10px) rotate(10deg) translateY(5px);
transform: perspective(500px) translate(10px, 0, 20px) rotateY(3deg);

/* Global values */
transform: inherit;
transform: initial;
transform: revert;
transform: revert-layer;
transform: unset;

The transform property may be specified as either the keyword value none or as one or more <transform-function> values.

You can watch this article for more details: developer.mozilla.org

CodePudding user response:

the class is box1 and you write box:hover it should be box1:hover.

<style>
 .box1{
   height: 100px;
   width : 100px;
   background-color:red;
   transform: translateX(10px) scale(2) rotate(45deg);
}
.box1:hover{
  transform: none ;
}
</style>
  • Related