Slide one div up when another div is hovered over

I have a block named case-card with a child division called case-card__wrapper that contains text.

When hovering over the case-card, I would like the case-card__wrapper to subtly move upwards in a transition, rather than abruptly jumping from one position to another.

While I believe I understand the concept, I am uncertain about how to properly implement the transition effect. Currently, it appears to simply shift from one location to another without any smoothness:

.case-card {
    height: 560px;
    width:600px;
    color: #ededed;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    transform: translateY(20px);
    transition: all .3s ease-in-out;
    background-color: #333; 
    overflow: hidden;
}
.case-card__wrapper{
    position: absolute;
    transition: 0.5s;
    /*top: 0; Don't want to add this because I want the text to be centered in the div and rather not define a number since the div heights may vary  */
}
.case-card__title{
  font-size: 16px;
}
.case-card:hover .case-card__wrapper {
  top: 150px;
}
<div class="case-card">
  <div class="case-card__wrapper">
    <h4 class="case-card__title">Title</h4>
    <p class="case-card__subtitle">Subtitle</p>
  </div>
</div>

I'm attempting to achieve this effect using only CSS. Any suggestions?

Answer №1

If you're having trouble setting the initial value, consider using transform instead. You can also eliminate position:absolute

.case-card {
    height: 560px;
    width:600px;
    color: #ededed;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    transform: translateY(20px);
    transition: all .3s ease-in-out;
    background-color: #333; 
    overflow: hidden;
}
.case-card__wrapper{
    transition: 0.5s;
 }
.case-card__title{
  font-size: 16px;
}
.case-card:hover .case-card__wrapper {
  transform:translateY(-100%);
}
<div class="case-card">
  <div class="case-card__wrapper">
    <h4 class="case-card__title">Title</h4>
    <p class="case-card__subtitle">Subtitle</p>
  </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

Transform HTML elements within an *ngFor iteration based on a specific variable in Angular 4

In my current project using Angular 4, I am faced with the task of dynamically modifying HTML tags within an *ngFor loop based on a variable. Here is the code snippet that represents my approach: <mat-card-content *ngFor="let question of questionGrou ...

Click the button to automatically insert the current time

Hello, I am new to scripting and seeking some guidance. I have a code that retrieves the current time and sends it to a MySQL database when a button is clicked. <form action="includes/data_input.inc.php" method="POST"> <!-- button - Start ...

Setting minimum date on Bootstrap datepicker in Asp.net core: A quick guide

This form uses the native bootstrap datepicker input. I'm trying to establish a minimum date that the user cannot select by clicking, but my current method is ineffective. What is the correct approach to make this function properly? Here is the cod ...

What is the best way to expand a div in a downward direction exclusively?

My task involves a parent div containing a centered child div. My goal is to have the child div grow downwards only upon clicking it, not in both directions. Initial state of the two divs: https://i.sstatic.net/cWYyV.png Outcome after clicking on div 2: ...

What is the best way to duplicate several HTML input fields using jQuery?

My div is quite intricate with input fields structured like this <input type="text" name="firstname"> <input type="text" name="lastname"> <input type="text" name="email"> <input type="text" name="address"> <div id="section_toC ...

Tips for modifying the "width" of a style within an HTML template implemented in a NodeJs express application

Currently, I am facing a challenge in dynamically adjusting the width value for a <div> element serving as a coloured bar within an HTML template used for PDF generation. While I can successfully set other values using something like {{my_value}}, ap ...

Live visualization from a Remote System (External Network)

I am looking to visually represent real-time sensor data (streaming data) using Node.js, HTML, and MySQL. I have set up MySQL to store the real-time sensor data, an index.html file that implements Google Chart through the doPoll app.js file, and the app.js ...

What steps can I take to make this menu more leisurely?

I've been experimenting with creating a horizontal menu using HTML and CSS. <section class="latest-albums-area section-padding-100"> <div class="container"> <div class="row"> ...

What is the process for generating a subpage within the main page without the need to navigate away from the primary

On my main page, I have a login button. Instead of redirecting the user to a new page, I want it to simply display a login box. You can see an example of this on medium.com when you click on 'sign in'. Is it possible to achieve this with only HTM ...

Solving the right-to-left orientation issue in the Bootstrap navbar

I have implemented a navbar using the code below, which aligns well from the right side. However, the menu items are sorted in ltr order and I need them to be in rtl order, so that "Dropdown 1" starts from the right side of the page. Currently, it appears ...

Adding and removing form fields in a table dynamically using AngularJS

I need to dynamically add multiple form fields when a button is pressed, and I want all the fields to be displayed in a table format (each field should have its own space in a <td>field</td> structure). Currently, I am facing an issue where if ...

Incorporating CSS and JS files into a WordPress theme

To incorporate Css & Js files into my website pages, I plan to insert the following code into the functions.php file: function cssjsloading(){ wp_enqueue_style('bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.css&apo ...

The slide experiences overflow as it continuously slides up and down

Hey everyone, I've been working on creating a slider effect when a button is clicked. Details about a specific part appear in a designated div upon button click. However, I've encountered a bug where, if I click quickly on different slides, the c ...

Can someone explain the method for displaying or concealing a menu based on scrolling direction?

https://i.stack.imgur.com/tpDx0.jpg I want to hide this menu when scrolling down and show it when scrolling up. The code for my menu bot is: <script> var previousScroll = 0; $(window).scroll(function(event){ v ...

displaying the identical image from various perspectives

I have an arrow image that I need to display in different angles - top, left, bottom, right. I was considering what would be the best approach: 1: Changing the image direction via CSS and loading the main image <img src="a.png"> <img src="a.png" ...

Switch the dropdown menu to a button if it consists of only one option

I have been using a database within the Moodle Learning Management System that generates a bootstrap table. Here is an example of what it looks like: https://i.sstatic.net/UJc4M.png The last row in the table contains a dropdown menu. When viewing your ow ...

Creating my very own slider

I'm currently working on a slider and encountering a few challenges. 1) The animation on the first slide isn't functioning as expected. 2) The spacing for the last box initially appears incorrect, but adjusts as the slider progresses. 3) I&apo ...

Validation with HTML5 required before submitting using AJAX

I'm facing a dilemma with my html5 form and ajax submission. Whenever an invalid value is entered, a popup message alerts the user. How can I validate the entries before triggering the ajax submit? Form: <form id="contactForm" onsubmit="return fa ...

Is it necessary to install only form control styles from Bootstrap 4?

Does Bootstrap 4 offer a way to only install the form control styles like input group? I came across a resource that allows you to solely install the Bootstrap 4 Grid. Is there anything similar for downloading just the form styles? ...

Is it possible to use a base64 encoded animated gif as a background in CSS

I embedded an animated gif into my CSS code like this: .magicBg { background-image: url(data:image/gif;base64,R0lGODlhAQBkAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0ND ... } This animated gif is set to play only once. However, after the ...