Ways to move upward from a lower position

I am trying to create a hover effect where the title and content move to the right position upon hovering.

The issue I am facing is that the transition on the `Title` class is not working, and as a result, the hover effect is also not functioning properly.

What I attempted to do was change the hover behavior so that when hovering over the `ImageText` class, both the Title and Content move to `top: 0;` and `position: relative;`, which does work but without the desired transition effect. However, the problem arises when I should only hover over the `Title` class for the transition to occur.

.Section {
  display: grid;
  grid-template-columns: 1fr 5fr 1fr;
  transform: translateY(30px);
}

.Column2 {
  grid-column: 2;
  display: grid;
  grid-template-rows: 200px 200px 200px;
  grid-gap: 1em;
}

.two {
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  grid-column-gap: 1em;
}

.ImageText {
  position: relative;
  background-size: 100%;
  color: white;
  overflow: hidden;
  transition: 0.5s;
  height: 100%;
}

.Title:hover+.Content {
  position: relative;
  top: 0;
}

.Content:hover {
  position: relative;
  top: 0;
}


/* .Title:hover {
          position: relative;
          top: 0;
        } */

.Content:hover+.Title {
  position: relative;
  top: 0;
}

.Title {
  background-color: rgba(0, 0, 0, 0.6);
  font: caption;
  position: absolute;
  bottom: 0;
  width: 100%;
  transition: 0.5s;
}

.Content {
  background-color: rgba(0, 0, 0, 0.6);
  position: absolute;
  top: 100%;
  height: inherit;
  transition: 0.5s;
}
<div class="Section">

  <div class="Column2">

    <div class="two">

      <div class="ImageText" style="background-image:url(https://i.ibb.co/6Rvr53T/1.jpg)">

        <div class="Title">
          SpaceX's Next Starship Prototype Taking Shape
        </div>

        <div Class="Content">
          Construction of the test craft is proceeding apace, as two new photos posted o...
       </div>

      </div>

      <div class="ImageText" style="background-image:url(https://i.ibb.co/F87mkdk/3.jpg)">

        <div class="Title">
          NASA's Juno Mission Cheks Out Eclipse on Jupiter
        </div>

        <div Class="Content">
          All is well on our largest neighbor; NASA's Juno spacecraft just managed to s...
          </div>

     </div>

   </div>

</div>

The desired outcome is that when hovering over the Title, both the Title and the Content should move up to `top: 0;` with a transition duration of `0.5s`.

The solution needs to be achieved using CSS only, without any JavaScript.

For better visualization, it is recommended to view the full page when running the code snippet.

Answer №1

Give this a try or something similar. Place the Content blocks inside the Title blocks.

    .Section {
      display: grid;
      grid-template-columns: 1fr 5fr 1fr;
      transform: translateY(30px);
    }
    
    .Column2 {
      grid-column: 2;
      display: grid;
      grid-template-rows: 200px 200px 200px;
      grid-gap: 1em;
    }
    
    .two {       
      grid-row: 2;      
      display: grid; 
      grid-template-columns: 1fr 1fr 2fr;       
      grid-column-gap: 1em;
    } 
    
    .ImageText {
      position: relative;
      background-size: 100%;
      color: white;
      overflow: hidden;
      transition: 0.5s;
      height: 100%;
    }

    .Title {
      background-color: rgba(0, 0, 0, 0.6);
      font: caption;
      position: absolute;    
      bottom: 0;
      width: 100%;   
    }
    
    .Title .Content {        
        max-height: 0;
        transition: max-height 0.25s;
        overflow: hidden;
    }

    .Title:hover .Content {      
      max-height: 500px;
      transition: max-height 0.5s;
      overflow: hidden;
    }
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
  <link rel="stylesheet" href="./Style.css" />
</head>

<body>


<div class="Section">

<div class="Column2">

  <div class="two">

    <div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">
        <div class="Title">
          SpaceX's Next Starship Prototype Taking Shape
          <div class="Content">
                Construction of the test craft is proceeding apace, as two new photos posted on Twitter today (Sept. 17) by
                company founder and CEO Elon Musk reveal.
          </div>
        </div>
    </div>

    <div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">

      <div class="Title">
        NASA's Juno Mission Checks Out Eclipse on Jupiter
        <div Class="Content">
            All is well on our largest neighbor; NASA's Juno spacecraft just managed to spot the shadow of Jupiter's
            moon, Io,
            passing over its marbled clouds.
        </div>
      </div>



    </div>

    <div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">

      <div class="Title">
        Europe Wants Ideas for Cave-Spelunking Moon Robots
        <div Class="Content">
            As NASA makes a big push to land humans on the moon's surface by 2024, the European Space Agency (ESA) wants
            to learn
            more about the lunar caves that lie beneath.
        </div>
      </div>

    </div>
  </div>
</div>
</div>
</body>

</html>

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

Is iOS Safari automatically filling all fields with identical information?

I'm in the process of creating a basic form that allows users to input their name/email and their friend's name/email. The code snippet can be found below. Interestingly, while most browsers autofill only the first two fields, iOS Safari on my i ...

What is the best way to retrieve the previously chosen item from an array?

I have successfully implemented dynamic pill tabs with one minor issue remaining. The most crucial aspect is that when I remove a pill, I want it to return to the previously opened tab. I have provided a StackBlitz example without routes on this page: -> ...

What is the CSS solution for eliminating a line break immediately following the first word?

While designing an email template in html/css for a mailing list, I encountered an issue where on mobile devices the line breaks after the first word for every paragraph. You can see an example of this problem here. The code for the email template was gen ...

To retrieve the first td element by clicking a button within the corresponding row using JQuery

This may seem like a straightforward inquiry, but despite my best efforts, I have been unable to find a solution. I am looking to create a function that will allow me to click a button located in the 3rd td element and display the text from the first td e ...

Beginner in CSS wanting to set background image for input field

I am working on incorporating icons into my project. The image I have contains an array of 16x16 icons at this URL: "http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1" Does anyone know how I can selec ...

Hovering over an image with CSS for a cool effect - altering the background and text

I'm experimenting with creating a mouseover effect on images where the background becomes dimmer and text appears on top. For example, you can take a look at this page and scroll down to see how the second set of images darken and display text when y ...

Troubleshooting a mysterious anomaly with a jQuery UI button

Would like to achieve something similar to this: http://jqueryui.com/demos/button/#icons When trying to replicate it, http://jsfiddle.net/p5PzU/1/ Why is the height so small? I expected a square shape but am getting a rectangle instead. What could be c ...

align items center with respect to my central element

Describing my issue might be a bit complex, but I'll give it a shot. I'm working on a website and have 3 div elements in the header for my navigation bar (burger menu / logo / social networks). I've used flex display with justify-content: be ...

What could be the reason my checkbox won't check using jQuery?

Currently, I am using kojs within my Magento 2 project. I have implemented a method that successfully shows and hides an input box based on user interaction. However, despite the function working as expected, the checkbox does not display its checkmark. D ...

Using jQuery, you can easily apply a new class to a div when it is

I'm currently facing an issue with adding a class of "active" to a div upon clicking it using jQuery. My goal is to apply the css class of active in order to give the button a distinct color (or the hover effect.) Unfortunately, I have been unsuccess ...

The color of the textbox does not remain when it is focused

I've developed a custom CSS button style, which you can see here: http://jsfiddle.net/karimkhan/SgTy2/ However, when I implement the same CSS within the <style> tags on my page, the effect is not the same. It looks like this: The actual CSS on ...

Emphasize multiple anchor points

I am looking to highlight two sections of a page simultaneously. Here is what I currently have: <li class="langLI" style="list-style-type:none"><a href="/non-discrimination-and-language-assistance##French">| French Creole</a></li> ...

Variations in the appearance of scrollbars on the x-axis and y-axis within a single <div> element

Let's say we have a div element like this: <div class="nav-menu"></div> I want to customize the CSS style for scrollbar using the ::scrollbar pseudo-element: .nav-menu::-webkit-scrollbar { width: 8px; background: white; ...

Prevent the selection of Single Origin and House Blend options once the user opts for Espresso

<td> <select class="type"> <option value="Espresso">Espresso</option> <option value="" class="">Cappuccino</option> <opti ...

Adjust color scheme of drop-down menu

Having trouble changing the background color for my drop down menu. I tried to change the color for the sub div but it's not working. Can anyone help me fix this issue? Here is the code snippet: http://jsfiddle.net/3VBQ6/4/ #nav li:hover ul.sub li { ...

Django notification: Received request for GET /%7B HTTP/1.1

Every time the console refreshes, I see the message below displayed between once a second and 10 times a second: "GET /%7B HTTP/1.1" 404 26453 This issue seems to be connected to a carousel image strip in my code because it interferes with the timer a ...

Execute the function once the audio has finished loading

I need help running a function once an audio file has finished downloading. This is my JavaScript code: // https://freesound.org/people/jefftbyrd/sounds/486445/ var audioFile = "https://raw.githubusercontent.com/hitoribot/my-room/master/audio/test/test.m ...

Leveraging CSS to automatically number nested sections

Assume we have an example HTML or XML document structured like this: <body> <section> <h1>This should be numbered 1</h1> <section> <h1>This should be numbered 1.1</h1> <p>blah& ...

What is the best way to showcase a Table and an Image side by side in HTML using inline

Can someone help me figure out how to align my image and table on the same level? I've been struggling to get "inline-block" to work. :( <p id="play"> hey </p> <div id="menu"> <table> <tr> <td>Models</td& ...

What is the best way to connect images within my database?

Struggling to come up with a title for this question, but I'll do my best to explain clearly. I'm working with PHP & HTML and using a MYSQL Database. So, on my member site, each new member is assigned a random football player as their avatar fro ...