What is the best way to keep a heading anchored to the bottom of an informative hover container when using a transform scale effect?

I'm trying to make the title stay at the bottom of the hover box when a user hovers over it. I want the hover box to appear with the title always at the bottom, and close upwards from the title as the description covers the entire box. How can I achieve this without moving the title?

Below is the code snippet that illustrates the issue. When hovering over the h1 pictureTitle, it shifts towards the center due to the transform effect. What I want is for the title to remain at the bottom, and have the background of the hover box close upwards from the title, creating the illusion that the box is connected to the title.

.img__wrap {
    position: relative;
    height: 200px;
    width: 200px;
    overflow: hidden;
}

.picture {
    width: 200px;
    -moz-transition: all 0.3s;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
}

.img__description {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    color: #fff;
    opacity: 0;
    transition: opacity 0.2s;
    visibility:hidden;
}

.img__wrap:hover .img__description {
    opacity: 1;
    background:black;
    height:100%;
    visibility:visible;
    transition-delay: 0.5s;
}

.img__wrap:hover .picture {
    -moz-transform: scale(1.8);
    -webkit-transform: scale(1.8);
    transform: scale(1.8);
}

.pictureTitle{
    background:black;
    height:50px;
    width:200px;
    position:relative;
    bottom:70px;
    text-decoration:none;
    color:red;
}

<div class="img__wrap">
  <a href="myHomePage.html" style="text-decoration:none;">
    <img src="http://www.dogbreedplus.com/dog_names/images/puppy-dog-names.jpg" alt="hover box is supposed to encapsulate picture"
    class="picture">
    <p class="img__description">
      This is where the hover box should pop up explaining the picture it should flow from title and cover the box.
    </p>
  <h1 class="pictureTitle">Title</h1>
 
  </a>
  
</div>

Answer â„–1

1. Issue with Title staying at the bottom

The title is not moving along with the image resizing as expected. To fix this, you should adjust the bottom value of the pictureTitle from 70px to 0px and apply a transition effect. This will ensure that the title moves together with the image, always positioning itself at the bottom.

Your initial assumption about the question was incorrect. It is essential to move the title to avoid it remaining static in its original position.

2. Handling black background expansion from bottom to top

Another issue in your code involves transitioning from visibility:hidden to visibility: visible. This type of animation for non-numeric values like visibility:hidde/visible or display:none/block is not feasible. Instead, utilize opacity:0 and opacity:1 on hover effects.

To achieve the desired result, position the img__description at the bottom (bottom:0 without top:0) and set an initial height of 0px, then increase the height to 100% on hover.

If you need further assistance or have any other questions, feel free to ask. Cheers! :D

.img__wrap {
  position: relative;
  height: 190px;
  width: 200px;
  overflow: hidden;
}

.picture {
  width: 200px;
  -moz-transition: all 0.3s;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
}

.img__description {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  color: #fff;
  opacity: 0;
  transition: 0.2s;
  margin: 0;
  background: black;
  height: 0;
}

.img__wrap:hover .img__description {
  opacity: 1;
  height: 100%;
  transition-delay: 0.5s;
}

.img__wrap:hover .picture {
  -moz-transform: scale(1.8);
  -webkit-transform: scale(1.8);
  transform: scale(1.8);
}

.pictureTitle {
  background: black;
  height: 50px;
  width: 200px;
  position: relative;
  bottom: 70px;
  text-decoration: none;
  color: red;
  transition: 0.5s;
}

.img__wrap:hover .pictureTitle {
  bottom: 0;
}
<div class="img__wrap">
  <a href="myHomePage.html" style="text-decoration:none;">
    <img src="http://www.dogbreedplus.com/dog_names/images/puppy-dog-names.jpg" alt="hover box is supposed to encapsulate picture" class="picture">
    <p class="img__description">
      This is where the hover box should pop up explaining the picture it should flow from title and cover the box.
    </p>
    <h1 class="pictureTitle">Title </h1>

  </a>

</div>

Answer â„–2

For optimal results, it is recommended to use an image of 200x200 dimensions when adjusting height. In the meantime, you can add height:200px to the class .picture in order to resolve any stretching issues with the image. However, a more suitable solution would be to utilize a perfect image sized at 200x200.

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 it possible to make the `<body>` element respect the offset (i.e. the user's current scroll position) when the 'custombox' modal is triggered?

I'm currently facing an issue with the scroll bars in the browser while using custombox.js in combination with BS4. Let me provide some context: I am working with a Custombox modal, which is similar to a BS4 modal. When a modal is opened in BS4, a c ...

Leveraging the CSS-Element-Queries Library for emulating the functionality of CSS media queries

Recently, I used a nifty CSS-Element-Queries tool to perform basic element manipulations that trigger whenever the window is resized. In simple terms, my goal was to dynamically adjust an element's attribute based on the current width of the window â ...

CSS dropdown menu - overlapping elements an issue?

Discover our test server here: Check out the box labeled "Organizers" on the top right corner... I've been struggling to bring the drop-down menu to the front layer. I've experimented with positioning and z-index, but so far, no success... Any ...

Creating a Gulpfile.js that efficiently manages a multitude of files spread across various folders

For my ongoing WordPress projects, I am simultaneously working on themes and plugins. In my theme folder, I have a gulpfile.js that compiles .scss files into .css. I am considering creating a central "master" gulpfile in the root folder to compile .scss fi ...

Struggling to align text to the far left within a text area using Bootstrap

When I accidentally place my cursor earlier in the text area, it starts writing from that point, leaving some unwanted spaces at the beginning. I prefer it to start from the extreme left, similar to how it behaves in input boxes. Below is the code snippet ...

How do I create more space in Vitepress to prevent the text from feeling cramped and allow it to display in a larger area?

Below is the content of my index.md file: --- # https://vitepress.dev/reference/default-theme-home-page layout: home hero: name: "TP2" text: "Analyzing the code of TP2 by Breno Mazzali Medeiros Tomazelli and Philippe Bouchard" ta ...

a practical guide on implementing overflow-x in the row class

How can I implement a row scroll overflow on the x-axis for columns 5, 6, and 7? <div class="container-fluid"> <div class="row"> <div class="col-4">col 1</div> <div class="col-4">col 2</div> ...

Is there a way to position the search bar on a new line within the navigation bar when the screen size is at its maximum width for mobile

I have a search bar on my navigation bar, but I am looking to move it to the next line within a maximum width if the screen display is extra small (xs) or for mobile devices. Below is the code snippet: <nav class="navbar navbar-expand-md fixed-top ...

Material-UI: The Mystery of Missing CSS Properties

Struggling to apply a CSS class to an element from Material-UI: bw:hover { -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */ filter: grayscale(100%); } Tried using makeStyles: import { makeStyles } from '@material-ui/core/styles' ...

Generating SVG images that show up as black in light mode and switch to light colors in dark mode

I am currently working on a website that has the option to switch between light and dark mode, and I need my logo to adjust accordingly. The black elements of my logo should appear black in dark mode and light in light mode. I attempted using the CSS cod ...

What are some solutions for troubleshooting a responsive image that functions correctly in Firefox but not in Chrome and Safari?

My row contains several img elements with height-capped sizes, displaying properly on Firefox but stretching on Chrome and Safari. Firefox Chrome Safari HTML: <div class="container-fluid text-center" style="padding-top: 15px"> <h6 class="ca ...

Hover over the drop-down menu to enable tab on hover mode

Is it possible to make the tab switch to hover mode when I rollover the drop down sub-menu without using JavaScript, and only using CSS? <li id="anchor" class="title dropdown"><a href="#">Main Tab</a> <div class="co ...

My @media queries are causing me some issues

Struggling with my @media queries. Once I upload my website on github, it fails to scale properly. However, when testing it in Webstorm (JetBrains), everything seems to be working fine. Any assistance would be greatly appreciated! Here is the link to my w ...

A sticky sidebar in HTML that is confined to a specific div element

I'm working on creating an HTML sidebar that is constrained to the size of a div (not full-screen like typical sidebars) and also sticky. This means that when the height of the div exceeds the screen's height, the sidebar should stick to the scre ...

Experimenting with jQuery in a .php file on a local server but experiencing issues with functionality

Currently, I am working on a login page that involves a specific functionality. When the user clicks on the "I'm a Student" button, I want to achieve a slideDown effect to hide one div and show another div with a slideUp effect. While I have confidenc ...

Is anyone else experiencing issues with loading a font from a CDN? It works perfectly fine on Chrome Browser and Safari for iOS Simulator, but for some reason, it's not loading

It's driving me a bit crazy as I'm not sure where I've gone wrong. I'm currently working with NextJS and have loaded this font into my <Link />. While it displays perfectly on Chrome and Safari in the iOS simulator, it fails to l ...

Size of text Including line breaks

I have developed a function that calculates the maximum size of text: function CalculateMaxTextSize(width, height, text) { var ourText = $('span').css('font-weight', 'bold').text(text); ...

The Bootstrap modal will not appear when the parent container's position is fixed

I am having an issue with a bootstrap modal that I am using as an instruction guide. My goal is to keep it fixed at the top-right corner of the viewport, so I tried using the fixed position. However, when I do this, the modal turns grey. On the other han ...

Displaying a success dialog after closing a Bootstrap modal

I have set up a bootstrap modal containing a form. Upon submitting the form, the form content is hidden and a bootstrap alert message is displayed. However, upon clicking the bootstrap popup, the same alert message is shown in the popup instead of displayi ...

What is the process for adjusting the text font within a fa-border element?

If you're interested, I have created a site template using only HTML5 and CSS3 which you can find here. For Font Awesome 5, instead of the SVG with JS version, I opted for the CSS webfont option. A clever trick I discovered was using <span class= ...