Hover activates a CSS animation where elements pop over other elements

I want to design a menu that resembles those "apps panels" we often see.

My menu consists of 6 elements, arranged side-by-side with no space between them. When I hover over an element, it slightly pops as shown in the code snippet below:

#account-bubble .account-param {
margin: 0;
padding: 0;
position: absolute;
display: inline-block;
width: 60px;
height: 60px;
border: 1px solid #CCC;
background: #F7F7F7;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: transform;
transition-property: transform;
z-index: 0;
}
#account-bubble .account-param:hover, #account-bubble .account-param:focus, #account-bubble .account-param:active {
-webkit-transform: scale(1.2);
transform: scale(1.2);
z-index: 5000;
}

.p1 {
top: 15px;
left: 15px;
}

.p2 {
top: 15px;
left: 74px;
}

.p3 {
top: 15px;
left: 133px;
}

.p4 {
top: 74px;
left: 15px;
}

.p5 {
top: 74px;
left: 74px;
}

.p6 {
top: 74px;
left: 133px;
}

#account-bubble .profile-picture img {

}

#account-bubble .account-param {

}
<div id="account-bubble">
<div class="account-param p1">
</div>
<div class="account-param p2">
</div>
<div class="account-param p3">
</div>
<div class="account-param p4">
</div>
<div class="account-param p5">
</div>
<div class="account-param p6">
</div>
</div>

To achieve this, I had to set the position of my elements to absolute and then adjust their positions by 1px to prevent a 2px border overlap. However, upon hovering over an element, the z-index resets immediately upon cursor exit, resulting in a jarring "unhover" animation.

Looking for suggestions on how to improve this effect or any alternative methods using CSS. Thank you for your assistance.

Answer №1

To gradually decrease the z-index, you can utilize the transition property.

-webkit-transition-property: transform, z-index;
transition-property: transform, z-index;

If you prefer to have different hover on/hover off effects, you have that option as well.

#element {
    /* HOVER OFF */
    -webkit-transition-property: transform, z-index;
    transition-property: transform, z-index;
}

#element:hover {
    /* HOVER ON */
    -webkit-transition-property: transform;
    transition-property: transform;
}

Answer №2

When using transitions, remember that the z-index property is animatable, so be sure to include it in your transitions by setting transition-property: all;

#account-bubble .account-param {
margin: 0;
padding: 0;
position: absolute;
display: inline-block;
width: 60px;
height: 60px;
border: 1px solid #CCC;
background: #F7F7F7;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
    /* change the transition-property to all */
-webkit-transition-property: all;
transition-property: all;
z-index: 0;
}
#account-bubble .account-param:hover, #account-bubble .account-param:focus, #account-bubble .account-param:active {
-webkit-transform: scale(1.2);
transform: scale(1.2);
z-index: 5000;
}

.p1 {
top: 15px;
left: 15px;
}

.p2 {
top: 15px;
left: 74px;
}

.p3 {
top: 15px;
left: 133px;
}

.p4 {
top: 74px;
left: 15px;
}

.p5 {
top: 74px;
left: 74px;
}

.p6 {
top: 74px;
left: 133px;
}

#account-bubble .profil-picture img {

}

#account-bubble .account-param {

}
<div id="account-bubble">
<div class="account-param p1">
</div>
<div class="account-param p2">
</div>
<div class="account-param p3">
</div>
<div class="account-param p4">
</div>
<div class="account-param p5">
</div>
<div class="account-param p6">
</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

What is causing the collapsed-animation to malfunction in Vue3?

Why won't the transition animation function in vue3js? The animation does not appear to be working for me. I've implemented this library https://github.com/ivanvermeyen/vue-collapse-transition <template> <nav class="navbar color-d ...

Unable to interact with menu in Internet Explorer

I am facing an issue with my code that should create a dropdown menu when hovered on, but it is not working properly in Internet Explorer. Instead of dropping down the menu, IE pushes it to the right, making it impossible to interact with. Surprisingly, th ...

Creating a dual-column checkbox design with CSS only

I'm working with a dynamically generated form element that can only be styled using CSS. I need help achieving a specific layout without making any HTML changes, except for the classes. The "element" and "formField" classes are common and cannot be mo ...

What is the best way to determine the position of an element with text content

Currently facing an issue with positioning in my project. Attached is a snapshot of my desired layout. I've tried creating a starburst effect and adding text using this code: jsfiddle link, but I'm struggling to position the elements correctly ...

Delete all anchor tags along with their contents in a MySQL database

Being a newcomer to the world of databases and SQL, I find myself in need of removing numerous links from specific MySQL databases. Although I have successfully created a REGEXP that can identify these entries, I am struggling to implement it with an UPDAT ...

Connecting mysql workbench data using html: A step-by-step guide

I'm currently creating a user interface for a database system using HTML. I'm a bit stuck on how to access and manipulate the database in MySQL Workbench. Does anyone have any suggestions or sample code that could help me connect them? Thanks! ...

Tips for setting a specific height for an HTML table

For some reason, I can't seem to control the height of this table. I've set it to a maximum of 20px but all the rows are still showing. Here is the CSS: table { border:1px solid black; overflow:hidden; height:20px; max-height:20 ...

Import of Bootstrap causing disruption in positioning of <figure> element

Check out this codepen example: https://codepen.io/anon/pen/Xgqjyq h2 { color: #111; font-family: 'Open Sans', sans-serif; font-size: 20px; font-weight: bold; text-align: center; } .content { margin-left: 5px; margin-right: 5px; t ...

Mobile version shows white spaces when using particles.js and bootstrap 4.6

This is how I implement particles.js: <div id="particles-js"></div> @RenderSection("Header", required: false) <main role="main" class="container"> @RenderBody() </main> <script> ...

The issue with Grid component in Nested Single file Component

I'm currently working on creating a grid component in Vue to set up a sortable and searchable chart using Single File Component. I've also integrated vue-router into the project. Below are my two .vue files. At the moment, I can only see the sear ...

Tips for utilizing the <img src> tag within Google Apps Script

I am trying to incorporate an image into a google apps script using the src attribute. I have specified the folder id and path, but unfortunately the image is not displaying as expected. The folder has been shared here for reference. Any assistance with t ...

using javascript to target a specific css selector attribute

I have a CSS file with the following code: .datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4; font-size: 16px ;font-weight: normal; } Is there a way to use JavaScript to dynamically change the font size? The code below worked ...

Tips for creating a unique custom UI headline using ReactJS, CSS, and bootstrap

Looking to create a design that is responsive in ReactJS using Bootstrap or CSS if needed. I need assistance with placing separators between columns and ensuring the values of each label are aligned in the same column but on the next line. The layout shoul ...

The tag's onclick function that was dynamically created was not triggering in jQuery

I created a web application using jquery mobile and ran into an issue. I am trying to call a function by clicking on a dynamically generated anchor tag, but it's not working and showing an error that the function is not defined. Any assistance on this ...

Attempting to enlarge logo or image when cursor hovers over it

Seeking to enhance logo/image size when cursor hovers over it, but facing an issue where it enlarges even on areas outside of the image itself - View Example. I followed a tutorial to achieve this effect, and specified the width as 1024x1024 for the logo/i ...

Tips for adjusting the size of icons in Ionic Framework v4 and Angular 7

The library ngx-skycons offers a variety of icons for use in projects. If you're interested, check out the demo here. I'm currently incorporating this icon library into an Ionic project that utilizes Angular. While the icons work perfectly, I&ap ...

The Bootstrap toast fails to appear on the screen

I am currently working on a website project using HTML with bootstrap and javascript. I have been attempting to include a toast feature by implementing the code provided on the bootstrap website: <div class="toast" role="alert" aria-live="assertive" ...

Use PHP to transform an array into JSON format, then access and retrieve the JSON data using either jQuery or JavaScript

I have successfully generated JSON data using PHP: $arr = []; foreach($userinfo as $record) { $arr[] = array( 'BAid' => $record->getBAid(), 'BCid' => $record->getBCid(), 'BA ...

Top methods for integrating custom divs into your WordPress site using PHP

As someone who is new to wordpress, I have a solid understanding of php, html, css and javascript. I am interested in integrating a custom font resizer into my wordpress site similar to the example shown below: https://i.stack.imgur.com/FwoIJ.jpg What w ...

I prefer boxes to be aligned next to each other without any gaps, and I won't be

In my quest to showcase 3 boxes seamlessly lined up in a row, I am faced with the challenge of eliminating spaces between them. My goal is to accomplish this feat without resorting to the font-size property. html,body { height:100%; width ...