How to apply unique CSS transitions (with transform) to both a parent and child element individually

My goal is to create a CSS-only "hover" transition where the hover state of one DIV animates another DIV and then animates multiple children inside the second DIV. It seems like I can't animate the child div if the parent is animated.

For example, consider a button on the left that, when hovered over, activates the transition/transform animation of the second div (a red half circle). I want the two half-circles to rotate at different times with different durations.

Check out the code snippet here: http://jsfiddle.net/dXCK6/2/


.mommy {
    width:300px;
    height:56px;
    background-color:hsla(40, 50%, 60%, .6);
    position:absolute;
    left:240px;
}
.daddy {
    visibility:visible;
    width:170px;
    height:170px;
    border-radius:50%;
    background-image: linear-gradient(90deg, hsla(10, 90%, 50%, 1) 50%, hsla(100, 90%, 50%, .0) 50%);
    position:absolute;
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
    -webkit-transition:0s;
    transition:0s;
}
.mommy:hover ~ .daddy {
    visibility:visible;
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
    -webkit-transition: .6s ease-in .2s;
    transition: .6s ease-in .2s;
}
.baby {
    width:150px;
    height:150px;
    border-radius:50%;
    background-image: linear-gradient(90deg, hsla(5, 35%, 50%, 1) 50%, hsla(100, 90%, 50%, .0) 50%);
    position: relative;
    top: 10px;
    left: 10px;
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
    -webkit-transition:0s;
    transition:0s;
}
.mommy:hover ~ .baby {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
    -webkit-transition: .1s ease-in .9s;
    transition: .1s ease-in .9s;
}

Please remember:

1) The positioning, visibility, and other elements in the jsfiddle must be included. 2) In the current example, the "baby" has a different transition time but it's not visible happening (this is the issue).

Answer №1

You may have mistakenly used the wrong selector (.mommy:hover ~ .baby), causing the animation for the .baby element to not run as expected. Instead, only the parent element .daddy rotates and in turn causes the child element .baby to rotate along with it. This visual effect might give the impression that both animations are happening simultaneously. Due to this confusion, it is unclear what specific effect you intended. To clarify, I have made some key modifications to demonstrate how both animations can function correctly when hovering:

/* Corrected selector for desired animation */
.mommy:hover ~ .daddy > .baby {
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
  -webkit-transition: .1s ease-in .9s;
  transition: .1s ease-in .9s;
}

Check out the updated demo here.

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

Avoid the div from covering the scrollbar within its containing parent div

Background: Trying to resolve an issue mentioned here: https://github.com/likeastore/ngDialog/issues/94 Challenge: If you open this plnkr link: http://plnkr.co/edit/qKJiNwyivqJVCAtyhwYR?p=preview and attempt to hold and drag the scrollbar with the mouse, ...

Think about using floated elements to determine the width of blocks

Consider this example HTML markup (link to jsFiddle): <div style="float: right; width: 200px; height: 200px; background-color: red; margin: 0 20px 0 30px;"> Block 1 </div> <div style="height: 100px; background-color: green;">Block ...

Could someone please assist me in identifying the issue with my CSS file? I am having trouble getting the primary color to display correctly in my HTML

I have incorporated a CSS style sheet found here: https://codepen.io/lorenzoyeung/pen/zYqxNQg However, when I attempt to implement the following code snippet, background-color: primary; border-color: secondary; the changes do not take effect. Can anyon ...

"Consolidating into one large package, Less is compiled and bundled together

Is there a way to display only the CSS being utilized on a webpage after it loads, rather than serving all compiled .less files as one big .css file? In addition, I am interested in having a sourcemap of the .less files shown in the browser for debugging ...

An effective method for modifying the active class on an li element in jQuery and ensuring that the user is directed to the desired page upon clicking the li element

I am facing an issue with my script tag. When I click on the links test.php or test2.php, the active class changes from index.php to the respective file but I am not redirected to the clicked page. I have tried solutions from various sources but none of th ...

td having no line breaks causing text to extend beyond the cell

I have a challenge with using the nowrap property on td elements to ensure proper formatting of my tables. In the first table, everything wraps nicely, but in the second table, the content in the first "td" exceeds its designated space due to length. How c ...

Incorrect font displayed on Bootstrap button after inserting hyperlink

This section contains my HTML code snippet: <div class="panel panel-default"> <div class="panel-heading"> Records <button type="button" class="btn btn-xs btn-success pull-right" id="command-add" data-row-id="1"> ...

CSS is functioning properly on a local level, but fails to take effect once the "npm run build" command is executed in the React application's build

I am attempting to override the CSS of Muidrawer-paper. It works locally after running "npm start", but it does not take effect when building the package. .css-12i7wg6-MuiPaper-root-MuiDrawer-paper { position: absolute !important; top: 50px !import ...

Mobile website menu selection

I want to create a select menu for my mobile website. I have added the select HTML code to my page. <select id="menu_mobile"> <option value="" selected="selected">Navigation</option> <option value="http://example.com/about"> Ab ...

Creating a sleek dark-themed table using Bootstrap's HTML

While browsing through https://getbootstrap.com/docs/4.0/content/tables/, I came across a table with a really dark background towards the bottom of the page. I tried copying the code into an HTML document, but it didn't seem to work. After tinkering w ...

The issue of React hover style malfunctioning in conjunction with Radium and Material-UI

I am currently utilizing the Radium library for inline styling in my React project. I have encountered an issue where the styling does not apply properly to Material-UI components, specifically when hovering over a Paper element. The color should change ...

Change the background color of a webpage by clicking with the help of Javascript

I've been experimenting with a script that changes the CSS background color on click, but I'm having trouble adding a third color option. Can anyone provide guidance on how to make the third color work? Check out my jsfiddle here: https://jsfid ...

"Position centrally on the inside, using flexbox to fill the entire

Seeking assistance with aligning the text in the center of the flexboxes so that the h4 and p elements in the large box are centered within their respective boxes, as well as ensuring the text in the two smaller boxes is also centered. Any help would be gr ...

Creating a ToggleButton in C#Is a Togglebutton the

I am trying to create a togglebutton for a website with Microsoft Visual Studio and am not sure if this would be the correct code to apply. I am working in C#, so the button is going to be generated in C# (and a bit of jquery) code and eventually styled in ...

Eliminate border-radius property from Bootstrap 4 breadcrumb using Sass styling

Within Bootstrap 4, there exists a Sass variable known as $enable-rounded which "Enables predefined border-radius styles on various components." (https://getbootstrap.com/docs/4.1/getting-started/theming/#sass-options) I need to eliminate the rounded ...

Ways to stop the floating label from blending with the input field

Attempting to incorporate the Bootstrap Material design theme into my project, I have implemented a basic text input field using the code below: <div class="form-control-wrapper"> <input class="form-control empty" type="text"></input> ...

Exploring with jQuery to discover the contents located at a specific X/Y position?

Hi there, I need help with the following code snippet: function getLocation() { var positionLeft = $('#element').position().left; var positionTop = $('#element').position().top; } I also have this line of code: $('ul#con ...

Accessing the current window dimensions using CSS

I'm experimenting with a way to set the background of the entire body element. <html> <head><head/> <body> <div class="wrapper"></div> </body> </html> How can I determine the height and width of the cu ...

Ways to Align an Item Horizontally within a Material-UI Typography Element

Struggling with centering the logo in an AppBar on extra small screens while using MUI V5 in a react project. The Typography component is nested inside a ToolBar within an AppBar that only displays on xs screens. Check out my code snippet below: <Box ...

Picking an art exhibit to visit

Can you provide recommendations for a gallery suitable for my web project? The project utilizes: jQuery Bootstrap An ideal gallery would be based on jQuery. Here are the requirements and preferences: Compact CSS and JavaScript files. Utilization of the ...