When the cursor hovers over the card, I want to show an image that stretches across the space above the footer and beneath the horizontal line, without spilling over the edges

I'm struggling with getting the hover image to fit the content area correctly. If I apply overflow: hidden to .card-content, it gets cropped to the size of the paragraph, and without it, the image overflows beyond the box. What I want is for div .card-content to fill the remaining space between the paragraph and the start of the card footer so that the hover image can occupy that area without overflowing. Any assistance on this issue would be highly appreciated. I am willing to set a height for .card-content and trim some of the image at the bottom or explore other workarounds. Here's the link to my current progress on CodePen: https://codepen.io/JeyDen44/pen/wvQdMyE

<style type="text/css">
body{
  padding: 2rem 0rem;
}

.card-body{
  padding: 1.25rem 0px;
}

hr {
  margin-left: 1.25rem;
}
.card-title, .card-subtitle, .card-text  {
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.card {
  height: 410px;
   display: flex;
  flex-flow: column;

}

.card-content {
  position: relative;

  flex: 1 1 auto;

}

.preview_image {
  display: none;
  width: 100% ;
  position: absolute;
  top: 0;
object-fit: contain;
}

.card:hover {
  .preview_image {
    display: block;
  } 
}
</style>
<div class="container">
  <div class="row">
    
    <!-- Card 1 -->
    <div class="col-lg-3 col-md-6 mb-5">
      <div class="card">
        <div class="card-body">
          <h4 class="card-title">1 Line</h4>
          <hr class="my-3" style="width:25px;border-top:3px solid #000">
          <div class="card-content">
          <h6 class="card-subtitle mb-2">Emilia-Romagna Region, Italy</h6>
          <p class="card-text">It is the seventh most populous city in Italy, at the heart of a metropolitan area of about one million people. </p>
             <img class="preview_image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Peacock_by_Nihal_jabin.jpg/220px-Peacock_by_Nihal_jabin.jpg" />
        </div>
        </div>
        <div class="card-footer text-danger">
          Test Bottom
        </div>
      </div>
      </div>
    
    <! -- Card 2 -->
    <div class="col-lg-3 col-md-6 mb-5">
      <div class="card">
        <div class="card-body">
          <h4 class="card-title">This is a test of 2 Lines of Text</h4>
          <hr class="my-3" style="width:25px;border-top:3px solid #000">
          <div class="card-content">
          <h6 class="card-subtitle mb-2">Emilia-Romagna Region, Italy</h6>
          <p class="card-text">It is the seventh most populous city in Italy, at the heart of a metropolitan area of about one million people. </p>
                                <img class="preview_image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Peacock_by_Nihal_jabin.jpg/220px-Peacock_by_Nihal_jabin.jpg" />
          </div>
        </div>
        <div class="card-footer text-danger">
          Test Bottom
        </div>
      </div>
    </div>
    
        <!-- Card 3 -->
    <div class="col-lg-3 col-md-6 mb-5">
      <div class="card">
        <div class="card-body">
          <h4 class="card-title">This is a test with 3 lines of text to display</h4>
          <hr class="my-3" style="width:25px;border-top:3px solid #000">
          <div class="card-content">
                                <img class="preview_image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Peacock_by_Nihal_jabin.jpg/220px-Peacock_by_Nihal_jabin.jpg" />
          <h6 class="card-subtitle mb-2">Emilia-Romagna Region, Italy</h6>
          <p class="card-text">It is the seventh most populous city in Italy, at the heart of a metropolitan area of about one million people. </p>

          </div>

        </div>

        <div class="card-footer text-danger">
          Test Bottom
        </div>
      </div>
    </div>
  </div>
</div>

your text

Answer №1

Simply include it within the ".card-body" category. This will effectively address your concern.

.card-body{
  overflow: hidden;
}

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

Achieving perfect alignment in a CSS grid for form elements vertically

One of my current projects involves creating a form layout using HTML and CSS that follows a Material Design style: <div class="form-group"> <input type="text" id="feedName" name="name" value={nameValue} onChange={this.handl ...

Dropping challenging shapes in a block-matching game similar to Tetris

I'm currently working on a game similar to Tetris, but with a twist. Instead of removing just one line when it's full, I want to remove all connected pieces at once. However, I've run into a roadblock when trying to implement the hard-drop f ...

What is the method for displaying an array in JavaScript?

When a user clicks the value 3 input box, three input boxes will appear where they can enter values. However, when trying to submit the array, no elements are printed and an error message "Element is not defined" appears. var arr = [0]; function get_va ...

Basic Chinese HTML Markup

As a college student, I find myself in the unique situation of taking two seemingly unrelated classes that have unexpectedly merged together - programming and Chinese language. In my C++ class, while learning to code in HTML, I took the opportunity to crea ...

CSS-Only tooltip that adjusts size dynamically

Having trouble getting a tooltip to work exactly as desired? I need to implement tooltips for the contents of dynamically built HTML tables. It must be done with CSS only, without relying on JavaScript or events for performance reasons. The challenge is ha ...

Is there a way to adjust the position of ::before elements without affecting the border placement?

I'm struggling with an element that has a CSS style ::before to display an arrow-up inside a black circle. Check out the code here The issue I'm facing is that the character \25b2 isn't centered vertically within the circle. Adjustin ...

Create a div element within the parent window of the iFrame

I'm trying to figure out how I can click a button within an iFrame that contains the following code: <td class="id-center"> <div class="bs-example"> <a id="comments" href="comments.php?id=$id" name="commen ...

Fixed width blocks automatically adjusting to small containers

When I try to add text to my absolute block inner div, it doesn't expand as expected. I am aware that expanding within a parent container with a specified width, such as <div class="main_wrap"></div>, can be problematic. Unfortunately, I ...

Replacing values in an HTML file with MySql query results

----- Problem solved, solution below ----- In my HTML file, I have a dropdown menu for various courses listed as follows: <ul> <li class="dropbtn" id="1"> <a href="">first</a> <ul class="dropdown-content"> ...

Create an HTML component that expands to fill any leftover space on the page, without using flex

In my current situation, I have two elements positioned side by side with dynamic widths based on their content. The element on the right needs to fill up as much vertical space as possible without a set width. I am looking for an alternative to flexbox d ...

JavaScript animation not functioning properly when height is set to "auto"

Can someone help me figure out why setting the height to "auto" in the code snippet below isn't working as expected? I want the DIV to adjust its size based on the content, but it's not happening. Any ideas on how to fix this issue would be great ...

How can jQuery be utilized to enlarge specific <li> elements that are aligned with the right side of the page?

I'm encountering issues with expanding list elements using jQuery. The lists consist of social media icon links that I would like to enlarge upon mouseover. The problem arises when enlarging the width of the li element, causing the ul to also expand. ...

The mobile header appears without any background shading

Hey there, I'm encountering a puzzling issue: I have a header with a gradient background that displays perfectly on desktop. However, when I preview it on Chrome mobile emulator, it looks fine. But when I test it on an actual tablet or mobile device, ...

Adjusting the height of a div inside a Material-UI Grid using Styled Components

When the mouse hovers over the two cells highlighted in pink, they turn pink. Is there a way to make the entire grid fill with pink when hovered over, both width and height at 100%? Check out the sandbox here ...

Using R for web scraping, I encountered a unique situation where the 'next page' button was only programmed to navigate to the top of the page

I am attempting to extract the headline snippets from a local newspaper's articles by utilizing rvest and RSelenium. To access pages beyond the initial one, I need to click on the 'next page' button. Strangely, when I perform this action thr ...

The HTML input needs to include a particular phrase

When considering an input field that will capture a user's response, such as one labeled Linkedin URL, it is important to ensure the entered data meets specified requirements. For example, a user may mistakenly enter a different URL like facebook.com/ ...

I need to access a webpage using VBA without relying on Internet Explorer for logging in

I need to access the website by logging in. However, I am facing difficulty in using it. Unfortunately, I am unable to share the username and password due to confidentiality reasons. Below is the code snippet that I have: Sub checkdownload() Dim u ...

php Use cURL and the DOM to extract content with specified CSS styling

Unclear in the title, I want to copy all content from a specific div on an existing webpage (not owned by me). The code successfully extracts the content. Extractor code: // Get Data $curl_handle=curl_init(); curl_setopt($c ...

A curated list of Laravel form request validation resources

After researching, I couldn't find any information on how to validate collections in the documentation. In .NET Core, I can easily achieve this by creating a Model with data attributes that automatically bind to the front end model, displaying all err ...

Display an HTML table without generating a preview window or prompting the user

When attempting to print an HTML table using a button and onclick function, I am encountering a prompt window that requires me to click another button to initiate the printing process. Is there a way to print the table with just one button click, without a ...