problem with seamless transition during vertical sliding of div

Hey there! I'm trying to create a cool effect where two stacked divs inside a parent div slide up and reveal the one beneath it when hovered over. I've managed to make it work, but the transition is not as smooth as I'd like. It seems to flash when the mouse moves around. What I really want is for the top div to stay in place until the mouse leaves the area, and then smoothly slide back down to its original position. Below is the code snippet and a link to the jsfiddle. Any help or suggestions would be greatly appreciated!

HTML

<div class="block">
<div class="top"></div>
<div class="bottom"> Testing</div>
</div> 

CSS

 .block{
  height:304px;
  width:304px;
  overflow: hidden;
 }

 .top{
   top: 0;
   height:300px;
   width:300px;
   border: solid 2px rgba(0,0,0,0.08);
 }

 .top:hover{
  margin-top: -304px; 
  display: block;  
  -webkit-transition:.43s ease;
  -moz-transition:.43s ease;
  -ms-transition:.43s ease;      
 }


.bottom{
  color: #f8f8f8;  
  height:300px;
  width:300px;
  background-color: #CF222D;
  border: solid 2px rgba(0,0,0,0.12);
 }

Check out the jsfiddle here!

Answer №1

The reason you see this flickering effect is because the hover styles are only applied when hovering over the .top element. As the transition occurs, the hit-area of the .top element shrinks and is replaced by the .bottom element. When the .bottom element expands to where your mouse is, the CSS no longer detects that you are hovering over the .top element, leading to a reversal of the transition. This back-and-forth battle between the styles causes the flickering effect wherever your mouse is positioned.

To resolve this issue, you should apply the hover styles based on the state of the parent element, like this:

.block:hover .top {  }

You can view an example here: http://jsfiddle.net/4gBk2/5/

Note:

Additionally, it's recommended to place your transition styling within the .top{ } selector to ensure smooth sliding motions. This practice ensures that the transition is always active and not just applied simultaneously with its execution.

For another example, check out: http://jsfiddle.net/4gBk2/6/

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

Troubleshooting: The JavaScript code is not functioning properly for the textarea field in my select form

Greetings, I have been tirelessly searching for a solution to my problem with no luck. Here is the issue at hand: I am trying to set up a message board where users can select pre-made templates from a drop-down menu filled with static HTML tags. The goal i ...

Tips for making an appended element match the height of an image

After embedding the div .soonOverlay into specific .smallCatalogBlock's, I am facing difficulty in adjusting the height of soonOverlay to match only the height of the img within smallCatalogBlock. Currently, its height extends throughout the entire co ...

Using AngularJS to dynamically apply a CSS class to message text depending on the HTTP post response

I am looking to implement a method for adding a CSS class to the text color of a message based on the response. Currently, I achieve this by: if (response.data.status == 201) { angular.element(document.getElementById("msg")).addClass("text-green"); ...

Centering Vertical Tabs Using HTML and CSS

I followed a vertical tab tutorial on W3Schools and would like to implement it on my website. However, I am having trouble centering the tabs after reducing their width sizes. I have attempted adding div tags to the code and aligning them to the center wit ...

Applying CSS background styles to HTML elements for a visually cohesive grouping with rounded edges

Searching for a method to group HTML elements together with a background. The challenge lies in the rounded corners as shown in the image. Is there a way to successfully accomplish this task? ...

Is It Feasible to Create a Button with Angled Corners Solely Using CSS and Without Any Images?

https://i.sstatic.net/BE0ga.png Looking to create a button solely using CSS without any images? The challenge lies in the bottom-left and top-right corners, particularly when the button is on a non-solid background. Need help coming up with a universal so ...

The browser is disregarding the CSS rule set for the checkboxes

I am experiencing an issue with a div called "popup" that is supposed to display a popup menu with a checkbox labeled "more" for getting additional items. However, changing the properties of "#popup" or "overflow-y: scroll;" does not have any effect as the ...

I'm looking to design a button with text positioned beneath an icon using either Bootstrap 5 or CSS. How

Is there a way to create buttons like the ones shown in the examples using Bootstrap 5 or custom CSS classes? Examples: [Set of buttons][1] Notice how some of them function as dropdown buttons. I've searched for examples but most of them only show ...

Display a tooltip when you click on a different element

I have a unique feature that I want to implement on my website. The idea is to display a tooltip when a user clicks on a specific div with the same ID as the tooltip. This will be particularly useful for interactive questions where users can click and reve ...

Inequality in spacing between Bootstrap columns

I am currently working on a website where the home page has columns with icons and text. The issue arises on mobile devices as the columns stack unevenly due to varying text lengths, resulting in inconsistent vertical spacing. Is there a way to ensure cons ...

I want the hover effect to trigger specifically when I hover over the image within a column of a row using CSS

My issue lies with the hover effect on my webpage. Currently, the problem I am facing is that the hover effect activates whenever my mouse hovers over any part of the column in a row. How can I make it so that the effect only triggers when hovering over th ...

What is the best way to incorporate a solid element onto a see-through background?

I have a link at "http://hastebin.com/julayefoto.xml" and I need assistance in making the content inside the bubble named "Test Test Test" non-transparent while keeping the bubble itself transparent. Any help would be greatly appreciated. Thank you :) ...

Creating Visuals from Text with ReactJS/NextJS

Looking to transform text into an image with a shareable link in ReactJS, similar to Spotify's lyrics sharing feature. I haven't attempted any solutions so far. I've explored various libraries without success. ...

Override the default HTML style overflow to hidden with Material UI Swipable Drawer

Currently, I'm utilizing the Material UI SwipableDrawer component which has an unexpected drawback of causing the scrollbar to disappear when the drawer is displayed. This issue overrides my specified style of "overflow-y: scroll" on the Html tag and ...

Eliminate all blank spaces at the top and bottom of Span by squishing it

Imagine I have this code snippet: <span class="labels" style="background-color: #FFFFFF;border: 1px solid #000000;font-family: Verdana;font-size: 11px; ">74.58 ft.</span> I am looking for a way to compress the span element so that only the te ...

I only notice certain text after carefully inspecting the elements in Google Chrome

While creating an application on Sitefinity (ASP.NET), I encountered an issue where certain elements, such as button text and labels, were not loading correctly when running the application. However, upon inspecting the element, they appeared to be working ...

The tooltip in Bootstrap v2.3.2 is causing words to be cut right in half

The tooltip plugin is set up like this: $("#id").tooltip({ placement: 'top', trigger: 'hover', html: true, container: 'body' }); Is there a way to prevent this from happening? Appreciate any insights. ...

Steps to insert an h2 element within a MeanMenu container

My current project involves working on a website that utilizes the meanmenu plugin. I have been facing a challenge for the past two days in trying to display a title inside the mean menu container. Here is the HTML code snippet for the menu: ...

Blank space appearing at the bottom of webpage

I have a strange issue with my document where there is a small white gap at the end. Upon inspecting the element, it seems to be related to the body. Any suggestions on how to resolve this? ...

Creating a fixed navigation bar on the right side using Twitter Bootstrap

I'm attempting to incorporate 4 navigation buttons on the right side of a page, which when clicked will allow me to navigate to different sections within the same page, similar to a single-page design. To achieve this, I am including the following co ...