Animating an upward movement of a div nested inside another div

Recently delving into the world of web development with HTML, CSS, and JavaScript, I've encountered an issue that has me stumped. I can't seem to figure out how to move a div upwards when the mouse hovers over it within its containing div.

.profile-button {
  background-color: var(--secundairy-dark);
  width: 70px;
  height: 70px;
  border-radius: 35px;
  margin: 14px;
  cursor: pointer;
  transition: transform 0.2s ease, border-radius 0.3s;
}

.profile-button:hover {
  transform: scale(1.15);
  border-radius: 10px;
}

.profile-button:active {
  transform: scale(1);
  border-radius: 25px;
  transition: transform 0.1s ease, border-radius 0.1s ease;
}

.profile-button:hover>div:nth-child(1),
.profile-button:hover>div:nth-child(2) {
  transform: translateY(-10px);
}
<header style="background-color: grey;
                height: 100px;
                width: 100%;
                border-bottom-left-radius: 20px;
                border-bottom-right-radius: 20px;
                display: flex;
                align-items: center;">

  <div class="profile-button" style="overflow: hidden;">

    <div style="height: 30px;
                        width: 43px;
                        background-color: lightblue;
                        border-top-left-radius: 10px; border-top-right-radius: 10px;
                        transform: translate(13.5px, 43px);">
    </div>

    <div style="width: 30px;
                        height: 30px;
                        border-radius: 20px;
                        background-color: lightblue;
                        transform: translate(17.5px, -17px);
                        border-color: green;
                        border-width: 3px;
                        border-style: solid;">
    </div>

  </div>
</header>

Answer №1

Yes, the solution does work! However, it is recommended not to use inline styling for better code organization. I have recreated your example using classes instead of inline styles, and it appears to be functioning properly. I haven't delved into understanding the exact desired behavior, but give it a try.

.flex-center{display:flex;align-items:center;}
header{height:100px;width:100%;background-color:dodgerblue;color:white;border-bottom-left-radius: 20px;border-bottom-right-radius: 20px;}
.profile-button {
        background-color:red; /*  var(--secundairy-dark)  */
        width: 70px;
        height: 70px;
        border-radius: 35px;
        margin: 14px;
        cursor: pointer;
        transition: transform 0.2s ease, border-radius 0.3s; 
    }

    .profile-button:hover {
        transform: scale(1.15);
        border-radius: 10px;
    }

    .profile-button:active {
        transform: scale(1);
        border-radius: 25px;
        transition: transform 0.1s ease, border-radius 0.1s ease;
    }

    .profile-button:hover > div:nth-child(1),
    .profile-button:hover > div:nth-child(2) {
        transform: translateY(-10px);
    }

.pbSubOne{height:30px;width:43px;background-color:midnightblue;color:yellow;transform: translate(13.5px, 43px); border-top-left-radius: 10px; border-top-right-radius: 10px;}

.pbSubTwo{width:30px;height:30px;border-radius:20px;background-color:midnightblue;color:yellow;transform:translate(17.5px,-17px);border-color:blue;border-width:3px;}
<header class="flex-center">

        <div class="profile-button" style="overflow: hidden;">
            
            <div class="pbSubOne"></div>

            <div class="pbSubTwo"></div>

        </div>
</header>

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

The idea behind this jQuery and CSS 3 animation is to create a dynamic visual of moving along a road that disappears into the

At the outset, let's clarify that I am seeking a conceptual solution or approach rather than actual working code. The Issue at Hand I have been tasked with exploring a navigation concept for a timeline wherein you would walk down a road towards the ...

The div's style property now includes Tailwind Width set at 0px

Currently, I am developing a web application with Next.JS and Tailwind CSS for styling. In this project, I need to map over some "accords" related to perfumes and assign variable widths to each one based on the size property of the accord, which is a strin ...

Invoke a function within an HTML element inserted using the html() method

Looking for help with a JavaScript function: function toggle_concessions(concessions) { var text = "<table>"+ "<tr><td class='concession-name'>gfhgfbfghfd</td><td class='op-encours&a ...

Using Angular 4 to retrieve a dynamic array from Firebase

I have a dilemma while creating reviews for the products in my shop. I am facing an issue with the button and click event that is supposed to save the review on the database. Later, when I try to read those reviews and calculate the rating for the product, ...

Tips for adding a border-bottom a few pixels underneath a list item:

I'm working with a menu that has dynamic content. When a user clicks on a li tag, it receives the class "active". I want to show which class is active by adding a border-bottom to it, but I want the border-bottom to be positioned 5px under the li tag ...

Is it possible to apply a personalized scrollbar design to the Autocomplete Listbox component in Mui?

I am struggling to implement a custom scroll style in Autocomplete Listbox. https://i.sstatic.net/MifSm.png After multiple attempts and thorough research, I have been unsuccessful in achieving the desired result. Here is my most recent code: <Aut ...

Tips for achieving a div overlapping effect on another

<header> <div> <h1>Smith's Portfolio</h1> <hr /> <!--<p>Under construction</p>--> <nav> <ul> <li><a class="active" href="#">Home</a></li> <l ...

Issue of delayed loading of CSS in Vue.js application

My vue PWA is experiencing slow loading of CSS when using Vue Bootstrap and Buefy. I attempted to use V cloak, but it only hides components milliseconds after the raw HTML is briefly displayed without any CSS applied. I am looking for a method to display ...

Using jQuery to create a captivating Parallax Effect on your website's background image

Hey there! I have a div with the class 'section' that serves as a key element on my website. It has a background image set using the following CSS: .section-one { width: 100vw; height: 100vh; background-image: url(images/outside-shot ...

Excessive padding on labels and insufficient padding on input fields in Bootstrap 4 mobile view

Having a simple password field using Bootstrap grid classes: <div class="container"> <div class="row"> <label class="col-sm-2" for="passwordField">Password</label> <input class=&q ...

What is the best way to set values for DT checkboxes?

Is it feasible to set a value of TRUE/FALSE to an input type checkbox through JavaScript in a shiny app? Consider the scenario where there is a reactive data table: data:vals<-reactiveValues() vals$Data<-data.table( Brands=paste0("Brand&qu ...

Creating a structured database for products with a myriad of features

Imagine you are creating a searchable price database for a local pricelist, and encounter a scenario like this: For instance: You are searching for the product "Businesscard." "Businesscard" is the main product, but within it there are variations such as ...

Encountering an issue with the message "chartobject-1.render() Error >> Unable to locate the container DOM element." within a JavaScript function

I have encountered an issue while working with Fusion Charts in my HTML page using JavaScript. When attempting to display two charts simultaneously, I receive an error message that says: "fusioncharts.js:71 Uncaught RuntimeException: #03091456 chartobjec ...

Utilizing JQuery for handling dynamically created HTML tables

I am encountering an issue with my dynamically generated HTML tables. Each table row contains an Edit button, but the click event only seems to work for buttons in the first table and not for subsequent ones. How can I modify my code to ensure that the cli ...

Guide to refreshing a localStorage variable before transferring it to an Ajax request

I have a scenario where I need to update the localStorage value when an option is clicked from a list. The data-id value of the clicked option should be stored in localStorage and then sent through an Ajax call. However, the issue I am facing is that the l ...

Creating a split background with dual hues in a VUE project

I'm new to learning VUE and I'm trying to create a page where two different colors connect on the left and right with the same height. However, I'm running into issues where the colors don't align unless I add content to the right side. ...

Transform a binary large object (BLOB) file, specifically a music file, into a .WAV format using NODE.js on the server

I'm having difficulty grasping a basic concept. My Node server is successfully handling POST requests. I am sending a Blob to it (converting the blob to a .wav file). How can I save this Blob as a .wav file on disk? I want to use a music player to ...

Pandas now supports exporting data frames to HTML with the added feature of conditional

Is there a way to format a table in pandas where data in each column are styled based on their values, similar to conditional formatting in spreadsheet programs? An example scenario is highlighting significant values in a table: correlation p-value ...

Tips for maximizing website performance on touch-enabled devices

When using a touch device such as an iPhone, iPad, or Android device, it can be challenging to accurately tap on small buttons with your finger. So far, there is no universal method in CSS media queries to detect touch devices. As a workaround, I check if ...

What is the proper way to extract the value of a checked checkbox?

Currently, I am utilizing WordPress on my website and have implemented a loop that retrieves data from a database. Within the loop, there is a form element: <form action="" method="post"> ... function create(){ $sql = Select.... $res = $w ...