Adjust: Return scale to default

By applying transform: rotate(-2deg); to a section, I have created an effect where the section rotates slightly. Additionally, when the user hovers over the same section, it increases in size due to transform: scale(1.1);.

However, on one specific page of my website, I want to keep the rotation intact but eliminate the scaling effect when the user hovers over the section. Is there a method to reset transform: scale(1.1); without altering transform: rotate(-2deg);?

The complete code snippet is as follows:

section {
    display: block;
    width: 100px;
    height: 100px;
    padding: 10px;
    background: red;
    /* Rotate */
    -webkit-transform: rotate(-2deg);
    -moz-transform: rotate(-2deg);
    -ms-transform: rotate(-2deg);
    -o-transform: rotate(-2deg);
    transform: rotate(-2deg);
    /* Easing */
    -webkit-transition: -webkit-transform .2s ease-in-out;
    -moz-transition: -moz-transform .2s ease-in-out;
    -o-transition: -o-transform .2s ease-in-out;
    transition: transform .2s ease-in-out;
}
section:hover {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1);
}
.some-page section:hover {
    -webkit-transform: none;
    -moz-transform: none;
    -ms-transform: none;
    -o-transform: none;
    transform: none;
}

You can view the interactive demo on JSFiddle here.

Answer №1

To revert the original transform value on the hover selector, you can simply set it back to its initial state as shown below:

.some-page section:hover {
    -webkit-transform: rotate(-2deg);
    -moz-transform: rotate(-2deg);
    -ms-transform: rotate(-2deg);
    -o-transform: rotate(-2deg);
    transform: rotate(-2deg);
}

This will maintain the rotation at -2 degrees without triggering any scaling effects, thanks to the specificity of this selector over the generic hover selector.

section {
  display: block;
  width: 100px;
  height: 100px;
  padding: 10px;
  background: red;
  /* Rotate */
  -webkit-transform: rotate(-2deg);
  -moz-transform: rotate(-2deg);
  -ms-transform: rotate(-2deg);
  -o-transform: rotate(-2deg);
  transform: rotate(-2deg);
  /* Easing */
  -webkit-transition: -webkit-transform .2s ease-in-out;
  -moz-transition: -moz-transform .2s ease-in-out;
  -o-transition: -o-transform .2s ease-in-out;
  transition: transform .2s ease-in-out;
}
section:hover {
  -webkit-transform: scale(1.1);
  -moz-transform: scale(1.1);
  -ms-transform: scale(1.1);
  -o-transform: scale(1.1);
  transform: scale(1.1);
}
.some-page section:hover {
  -webkit-transform: rotate(-2deg);
  -moz-transform: rotate(-2deg);
  -ms-transform: rotate(-2deg);
  -o-transform: rotate(-2deg);
  transform: rotate(-2deg);
}

/* Just for demo */

section {
  margin: 10px;
}
<section>I'm some content</section>
<div class="some-page">
  <section>I'm some content</section>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you provide step-by-step instructions on how to customize styles with MUI in my application?

I am encountering issues with MUI while attempting to customize the color of my buttons. The two methods I have tried so far have been unsuccessful. For example, Method 1: import React from 'react' import { Typography } from '@mui/material& ...

Looking to place the bootstrap menu icon on the right side of the page

I have a bootstrap menu item on my website and I want to move the menu icon to the right corner of the page. How can I modify the code to achieve this? #menu { position: relative; color: #999; width: 200px; padding: 10px; margin: auto; font-fa ...

Set a CSS rule to style every other row in a table, starting from the second row and resetting after

Is there a way to refresh the even and odd count in CSS whenever a specific row is shown? Here's an example setup: header header header even even even odd odd odd Subhead Subhead Subhead even even even How can I ensu ...

Creating a compact Swiper slider: reducing image size without sacrificing full window coverage!

Utilizing Swiper to craft a slider that occupies the entire window, with a slight margin for a bar-- no issues there. () However, the image I placed in for the slide () appears to be excessively enlarged. Is there a way to display more of the width of th ...

What happens with the styling in this project when the CSS file is blank?

As a first-year CS student in university, I have been diving into the world of React.js. Currently, I am exploring a resume project and noticed that both app.js and index.js files are empty. I am curious to know how the styling is achieved in this project. ...

Refreshing the information in the database table

Upon receiving data from the server using ajax, I populate this table: $.each(data, function(i, item) { $('#MyTable tbody').append("<tr>" +"<td>" +data[i].A+ "</td><td>" +data[i].B ...

Button with embedded Bootstrap dropdown

I need help with centering a dropdown menu on my webpage. I followed the instructions, but it's still appearing next to the button instead of in the center. Below is the code snippet: <div class="btn-group"> <button type=" ...

Trouble with margins on tr elements and borders in CSS and HTML

Here are my current findings: http://jsfiddle.net/62hKs/2/ What I desire to achieve: 1) Create a 15px margin between the two red boxes displayed 2) Modify the appearance of the 4 boxes so they resemble only 2, by eliminating the middle red line caused ...

In the world of HTML5, you can find the <main> nestled within the <

Plot: As I was creating a coupons website, I came across the issue of incorporating non-unique content into the <main><article> ..here..</article></main>. Problem: Despite w3schools' statement : The content inside the eleme ...

Present XML data on an HTML page to generate interactive form features

I have an application that features a checkbox tree. I would like to automatically pre-select those checkboxes if the user had previously checked them. To achieve this, I receive XML data from my backend Perl script which contains information on which che ...

Enhance the functionality of the Bootstrap navbar by enabling the slideUp and slideDown effects

I can't get jQuery's slideUp and slideDown methods to smoothly animate the Bootstrap navbar. When I tried using the slideUp method, the navbar only slid up a little before disappearing completely, and the same issue occurred with the slideDown me ...

Adjust various text lengths to fit web browser content

I am using a web browser within my Windows Form. I am populating it with text each time, with almost the same text size in each loop. The size of my web browser is fixed, and I want to automatically adjust the text content to fit the browser. For example, ...

Guide to creating a dynamic column layout with minimum height divs

I am facing an issue with the variable height of my div, causing it to position incorrectly. To demonstrate the problem, I have included a code snippet below. Here is the solution I am seeking: https://i.sstatic.net/XMAMr.png Note: Since the div has a ...

Creating visually appealing website designs with Firefox by implementing smooth background image transitions using Javascript with

Currently, I am facing an issue with the banner area on my website. The background of the banner is set to change every 10 seconds using JavaScript. However, there seems to be a flickering effect that occurs for a brief moment when the background-image is ...

Navigating to the end of the fixed-height table while inserting new elements

I'm experiencing an issue with a function that adds new items to a table with fixed height and overflow: auto set. When new items are added, the scroll should immediately go to the bottom of the table. Unfortunately, this is not happening as expected. ...

Image carousel with interactive buttons

I've taken over management of my company's website, which was initially created by someone else at a cost of $24,000. We recently made some edits to the slideshow feature on the site, adding buttons that allow users to navigate to corresponding p ...

Using jQuery to apply gradient fill to SVG elements

Is it possible to create a gradient fill in an SVG with two or three colors dynamically? Currently, filling an SVG path with just one color can be done easily. Radial gradients are an option but don't offer much flexibility as colors have to be define ...

Expandable fluid inline svg that dynamically fills the remaining space alongside text within a flex row

How can I ensure that an inline SVG occupies all available space within a row without specifying its height across different screen sizes? The solution involves setting the SVG to have 100% height with a viewBox, allowing it to adjust accordingly while ma ...

Issue with the react-native-autocomplete-input where the list does not close after selecting an option

After selecting an item from the list in my react-native-autocomplete-input, the list does not close. let Location = (props) => ( <View style={styles.formItem}> <Autocomplete data={props.autocompleteResults.predictions} de ...

Random variable without repetition in SASS

I have a unique project where I am tasked with incorporating a list of 5 specific colors into 10 different div elements. The challenge is that each color must be used twice and in a completely random order without any repetition of colors. Although utilizi ...