The issue with the display grid position being set to absolute is causing functionality

Struggling to create an image catalog with cards containing text while using position absolute on the text and position relative on the card. Unfortunately, it's not working as expected.

/*catalog style*/
.grid-container{
    padding: clamp(5px,10vw,20px) clamp(5px,15vw,30px);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    grid-auto-rows: auto;
    column-gap: 40px;
    row-gap: 40px;
}

.card {
    position:relative;
    background-color: #EADDA6;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
    transition: 0.3s;
    border-radius: 20px;
  }
  
  
.card:hover {
    box-shadow: 0 16px 32px 0 rgba(0,0,0,0.2);
    opacity: 0.8;
    transition-duration: 0.3s;
}
  
.card img {
    position:relative;
    border-radius: 20px ;
    object-fit: cover;
}


     
.card-container {
    position:absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px 16px;
}
        <section class="grid-container">
            <div class="card" th:each="animal : ${animals}">
                <a href="animal.html">
                <img src="../static/public/animals/gwen-weustink-I3C1sSXj1i8-unsplash.jpg" alt="Avatar" style="width:100%">
                <div class="card-container">
                  <h4 th:text="${animal.getName()}"><b>Tiger</b></h4> 
                  <p th:text="${animal.getSpecies()}">Mario</p> 
                </div>
                  </a>
            </div>
        </section>

Attempted to use position relative on parent elements, however, the text remains below the card instead of inside it as intended. Display grid seems to work correctly without the positioning issues.

Answer №1

This solution is effective, but don't forget to specify the positions as left, right, top, or bottom. For instance, you can use position:absolute; left:0px; and top:0px;

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 send multiple HTML input values to a Google Spreadsheet using only JavaScript?

Seeking a faster and more efficient way to send the values of multiple HTML Inputs to a specific location in a Google Spreadsheet? The existing script takes too long to complete, often skips inputs, and relies heavily on "google.script.run". Due to softwar ...

Buffering ceases on the video

I am experiencing an issue with 4 videos and a preloader, which should hide once all the videos are fully buffered. <div id="preload"> <h1> Download... </h1> </div> <video preload="auto" class= ...

What is the best way to incorporate quotes within inline CSS code?

Can anyone help me with inserting the following CSS into HTML? Here is the CSS snippet that needs to be converted to HTML: .group .circular-progress::before { ... content: "10%"; ... } This is what I have attempted so far: <div class="group"&g ...

Controlling Javascript events

Currently, I am working on implementing an in-place editor using jQuery. The functionality is such that when you click on the text you wish to edit, it will replace the content with an input field, specifically a select tag. Everything seems to be functio ...

Selection list with limited comment choices

I am facing a challenge and would greatly appreciate any hints. I am working with a PHP loop to populate comments for a thread, like this: <tr><td>'.comment_date'.</td><td>'.comment_author.'</td><td> ...

Encountering a problem with ng-repeat when working with a JSON

Having a bit of trouble displaying the keys and values from a JSON object in an HTML table using ng-repeat. The JSON object is coming from the backend, but for some reason, it's not showing up on the frontend. I know there must be a simple mistake som ...

What are some ways to make the search bar on my website smaller in both length and width?

I have a WordPress website with the ivory search plugin installed for the search functionality. You can check out my website at www.osdoc.in. I am looking to make the search bar shorter and narrower as it is currently causing the menu icons to encroach on ...

Steps for placing an image within the boundary of a rectangular div

My div has a width of approximately 730px and a height of 50px. I am looking to place an image at the bottom of the div, exactly where its height ends - after 50px. I have been considering a query to append the image at the bottom. One solution could be ...

What is the latest CSS browser support for the min() and max() functions in 2018?

I am considering implementing the use of the min() and max() functions in my project. I'm curious about the current browser support as of 2018. Do you think it is necessary to include the @supports at-rule? For example, I could write: .px-4-safe { ...

Struggling to connect HTML with CSS in Hugo

I am experimenting with a pre-fabricated theme in Hugo and incorporating some Bootstrap codes. I want to change the color of all links when displayed or hovered over. Despite searching extensively, I have been unable to achieve this through the use of CSS ...

I am attempting to activate the HTML5 color picker's popup using JQuery

Is there a way to open a color picker in a popup window when an input[type=color] is clicked, using JavaScript? HTML <div id="customColorPick"></div> <input id="customColorPickInput" type="color" /> JQuery $("#customColorPick").click( ...

Exploring Anchor Tags in Next.js

I'm having trouble using an anchor tag in Next.js Despite not receiving any console errors when setting it up and clicking the link, the page doesn't scroll to the specified id tag. A recent GitHub issue implies that a significant amount of cus ...

How can I implement a Mouse Over event listener for a FlexTable in GWT 1.7?

What is the best method to attach an event listener or handler to widgets in GWT 1.7? I have looked at similar questions on SO, but they appear to be outdated. How can I add a Hover listener to a FlexTable, disregarding the existing :hover in CSS? ...

Retrieving information from the Header element (<H></H>) with the help of Selenium

I have a website with the following code snippet: <div class="list_item_normal"> <div class="main_content"> <div class="img_wrap"> <a href="/home/Detaljer/9781118093757"><img alt="Miniaturebillede af omslaget til Op ...

Step-by-step guide on embedding a function in HTML using vbscript

I'm working on a dynamic HTML list that I want to enable or disable based on user input. Typically, you can just use the "enabled" or "disabled" attribute at the end of the select element to control the entire list. However, I'm unsure how to ach ...

Issues with Jquery datatable causing column header to overlap the table header

I am facing an issue with my datatable as the table is not displaying correctly. Could someone advise me on how to troubleshoot and fix this problem? Below is the code snippet in question: $(tbName).dataTable({ "sScrollX": "100%", "sScro ...

Utilizing JQuery's .Toggle function in conjunction with a stylish CSS transform button

I am trying to create a toggle menu that shows and hides itself without requiring the button to be clicked twice. I have added e.preventDefault(); which solves the issue, but now the button does not transform as intended. $(document).ready(function() { ...

Trouble with AJAX communicating with PHP and not rendering fresh data

I have created a row of images that are clickable, and once clicked, a variable is sent via AJAX to a PHP file for a database query. The PHP file receives the variable and executes the correct query. However, instead of updating the HTML on my page, it sim ...

What is the best way to align my progress bar to the bottom of a button?

I've encountered a small issue that I'm struggling to resolve. My goal is to create a button with a Bootstrap progress bar at the bottom, but I can't seem to make it work as intended. Here's the current setup: https://jsfiddle.net/bob ...

Adjusting the width of the header in Wordpress themes like Genesis and Foodie Pro

Struggling with the header appearance on my website. I want the blue section to be full width while keeping the logo and navigation the same width as the content area (1040px). I'm new to Wordpress and unsure how to make this adjustment. Someone sugg ...