Tips on resetting the position of a flex box rotation

I created three flex boxes and added a transform that rotates 90 degrees when hovered over. However, I want to see it rotate back when I move my mouse away from the box. Here is the code:

#flex-container {
  display: flex;
  border: 2px solid black;
  padding: 10px;
  height: 300px;
  justify-content: space-around;
  flex-direction: row;
}

#flex-container :hover {
  cursor: pointer;
  border: 1px solid rgb(123, 251, 3);
  padding: 1px;
  transform: rotate(90deg);
  transition: 1000ms;
}

.flex-item {
  border-radius: 10px;
  background-color: purple;
  height: 50px;
  width: 50px;
}

.flex-item1 {
  border-radius: 10px;
  background-color: rgb(246, 166, 6);
  height: 50px;
  width: 50px;
}

.flex-item2 {
  border-radius: 10px;
  background-color: rgb(248, 71, 7);
  height: 50px;
  width: 50px;
}
<div id="flex-container">
  <div class="flex-item"></div>
  <div class="flex-item1"></div>
  <div class="flex-item2"></div>
</div>

Currently, it only rotates 90 degrees and stays there. What I really want is for it to rotate back 90 degrees when I move my mouse away. I am new to learning this so please excuse any mistakes in my language. Thank you.

Answer №1

Shift your transition effect from the hover state to the flex-items. This way, when you move your mouse away, the transition will revert.

Additionally, consider using a common class for your flex items to avoid repetitive CSS code.

#flex-container {
  display: flex;
  border: 2px solid black;
  padding: 10px;
  height: 300px;
  justify-content: space-around;
  flex-direction: row;
}

.flex-item {
  border-radius: 10px;
  height: 50px;
  width: 50px;
  transition: 1000ms;
}

.flex-item:hover {
  cursor: pointer;
  border: 1px solid rgb(123, 251, 3);
  padding: 1px;
  transform: rotate(90deg);
}

.flex-item--1 {
  background-color: purple;
}
.flex-item--2 {
  background-color: rgb(246, 166, 6);
}
.flex-item--3 {
  background-color: rgb(248, 71, 7);
}
<div id="flex-container">
  <div class="flex-item flex-item--1"></div>
  <div class="flex-item flex-item--2"></div>
  <div class="flex-item flex-item--3"></div>
</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

Thymeleaf allows for the splitting of tables across different pages when generating a PDF document

I have a custom HTML template containing a table structure <table id="people" border="1"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Salary</th> </ ...

Retrieving Blocked Images with Selenium: A Step-by-Step Guide

HTML: <html> <head> <body onload="document.getElementById('a').style.display='block';"> <div id="a" align="center" onclick="document.location.reload();" style="display: block; cursor: pointer;"> <img width="9 ...

Styling the Next and Previous Page Links in your WordPress Website

Currently working on developing my own custom Wordpress theme and everything is going well, except for one little detail. I am trying to customize the styling of my next/previous page links so that the next page-link appears on the right side and the previ ...

Having trouble with redirecting a website to its appropriate version for mobile or desktop users?

After creating both the desktop and mobile versions of my website, I have a question. How can I determine whether a visitor is using a mobile phone or a PC when they come to my website? Specifically, if a visitor accesses my website through a mobile devic ...

Are your macOS devices not displaying the Scrollbar CSS buttons correctly?

I need help troubleshooting why my buttons are not appearing in the scrollbar on macOS. They function properly on Windows, so I suspect there may be a typo or error in my code. Can anyone take a look and provide some insight? ::-webkit-scrollbar { wid ...

The final row continues to display the <div> element

Currently, I am in the process of learning PHP/MySQLi and there is something I need assistance with that I haven't been able to find a solution for online. In the forum script that I am developing, I have been using <div class="hr"> </div> ...

Unable to grab hold of specific child element within parent DOM element

Important Note: Due to the complexity of the issue, the code has been abstracted for better readability Consider a parent component structure like this: <child-component></child-component> <button (click)="doSomeClick()"> Do Some Click ...

Angular's nested arrays can be transformed into a grid interface with ease

I am looking to generate a grid template from a nested array. The current method works well if the elements naturally have the same height, but issues arise when values are too long and some elements end up with different heights. <div id="containe ...

Combining two CSS classes to create an "alias"

Currently, I’m utilizing bootstrap for table styling. For instance: <table class="table table-striped main"> However, the table I want to style is dynamically generated by a separate tool that I have no control over, and it already has its own ta ...

Ways to align anchor tags in the middle of a DIV element?

<div style="border: 1px solid rgb(0, 0, 0); height: 30px; width: 30px; background-color: rgb(245, 225, 130);"> <div style="margin: 5px;"> <a href="#link">#down2#</a> </div> </div> This is the current code I am w ...

Using jquery to remove textbox value when checkbox is unchecked

I have a single datatable created using jQuery. The first column of the table consists of checkboxes, and the last column contains textboxes. Because these elements are generated dynamically, they end up having identical IDs and names as shown below: $ ...

Header formatting issue when attempting to implement tablesorter plugin

I implemented the widget-scroller and widget column Selector in my table using the table sorter plugin in jQuery. Has anyone encountered a problem like the one shown in this picture? It seems that my table headers do not align with the columns properly an ...

Having trouble converting svg to png, thinking it might be due to discrepancies in svg elements

I am facing a puzzling issue where two different SVG elements are causing my JavaScript to work in one scenario but not the other. I have replaced the SVG elements in both examples, and surprisingly, only one works while the other does not. You can view th ...

Arrange images in a fluid manner around other images

Check out the website I'm currently working on: metroweb.tk I'm in the process of designing a website that mimics the Windows 8 metro UI. However, I've encountered an issue with larger app icons such as notes and clocks sticking out. Is the ...

What are some ways to ensure keyboard accessibility for a CSS drop-down menu?

I have come across some solutions, but I am struggling to incorporate them into my code as some require elements that are not compatible with my project. Let's get to the question: I need help making an existing CSS drop-down menu accessible for key ...

CSS: Apply unique padding to the last element without the use of additional classes

My challenge involves a div housing three images, each about 31% in width. The goal is to have padding between them, with the final image having no right padding so that collectively they match the width of a larger image above. Here's an example... ...

Fetching data using HTML script is not possible

Struggling to retrieve data from mongoDB and send it to the client side using res, but I keep getting undefined. Can anyone offer some assistance? Thank you all! //// server.js app.get('/user/show', userController.userList); //// controller cons ...

Creating an interactive text using Javascript functions

I am attempting to create an interactive text using JavaScript. While I can achieve this by creating a new function for each element, I realize that this approach will result in an excessive number of functions. Could anyone point out what is incorrect wi ...

SVG set to fill currentColor but does not dynamically change in high contrast mode

I'm currently working with in-line SVGs on my website. Here's an example: svg { fill: currentColor; } <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" height="25px" viewBox="-13 0 120 30" width="74px"> < ...

The background only partially covers the section

In a current project test using the provided template from , I encountered an issue when changing the section <section role="main" id="main"> to incorporate the carbon class as the background does not fill completely. My attempts to adjust the secti ...