Grid item overlay

Currently, I am facing an issue with React where I am attempting to place an overlay on top of each grid item in a grid. Despite trying multiple approaches, the overlay appears beneath each grid item instead of over it. Even setting the position: absolute does not seem to rectify the problem!

Below is the code snippet I am using for the grid (React):

  <div className="home__itemSection">
     <div className="item">
        <div className="item__container">
            <div className="container__imageDiv">
                <img
                    src={""}
                    alt=""
                />
            </div>

            <div className="container__detailSection">
                <p>{""}</p>
                <h6>{"&"}</h6>
            </div>
        </div>

        <div className="item__overlay">
            <h1>{""}</h1>
            <h1>{""}</h1>
        </div>
    </div>
  </div>

CSS:

.home__itemSection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    margin: 30px 170px 0 170px;
    transition: ease all 0.5s;
}

.item {
    background-color: #f1f1f1;
    height: 350px;
    width: 212px;
    margin: 0 3rem 1rem 3rem;
    height: fit-content;
    font-family: "Poppins", sans-serif;
    display: flex;
    align-items: flex-start;
}

.container__imageDiv {
    height: 318px;
    width: 212px;
}

.container__imageDiv > img {
    height: 318px;
    width: 212px;
}

.container__detailSection {
    height: 44px;
    width: 212px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding-top: 5px;
}

.container__detailSection > p {
    color: black;
    font-size: 13px;
    font-weight: 300;
    line-height: initial;
}

.container__detailSection > h6 {
    padding-left: 1.8rem;
    font-weight: 500;
    font-size: 1rem;
}

.item__overlay {
    height: 252px;
    width: 212px;
    background-color: black;
}

Any assistance on resolving this matter would be highly appreciated!
Thank you!

Answer №1

Ensure to include position: relative; in the CSS for the parent element of the overlay.

.item{
 position: relative;
}
.item .item__overlay{
   position: absolute;
   left: 0;
   top: 0;
}

Answer №2

When an element has the position absolute, it is positioned in relation to the nearest parent element with a relative (or absolute) position.

To ensure the entire container is covered, add the position: relative property to the home__itemSection class. Additionally, set the height and width properties to 100%:

.home__itemSection {
 ...
  position: relative;
}

.item__overlay {
  ...
  position: absolute;
  height: 100%;
  width: 100%;
}

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 there a way to extract the values from a range slider individually and then display them as the minimum and maximum values on the screen?

Currently, I am facing an issue with a range slider where the value I am retrieving is concatenated. For example, when printed, it appears as 2080, with 20 and 80 being separate values visually combined on screen. My goal is to extract the minimum and maxi ...

Center the logo between the menus in the foundation framework

Struggling to center the logo between menus using Foundation Zurb. I'm envisioning a layout similar to [menu1] [menu2] --[logo]-- [menu3] [menu4]. I believe utilizing the grid system may help achieve this: <div class="panel hide-for-small-down"&g ...

Trouble getting Node mailer to send out email messages

Having trouble setting up email verification using nodemailer. The user registration info saves in the database, but the email is not being sent. Can anyone offer a solution? I'm trying to generate a token first and then send it to the user for email ...

Retrieving all buttons from a webpage and removing those with a specific background-image using JavaScript

Hey everyone, I'm still learning about javascript and other web development languages. My current task is to locate all the buttons on a webpage and remove the ones that have a specific background image. I know about using getElementsByTagName but n ...

The SSR Next.js <Head> tag fails to render on the server side

import { getMeta } from '@/helpers/globalHelpers'; import Head from 'next/head'; import { useDispatch, useSelector } from 'react-redux'; import { increment, decrement, selectValue, bulkUpdate, reset } from '@/slicers/prop ...

Backend is currently unable to process the request

Whenever a user clicks on a note in my notes page, a request is supposed to be made to the backend to check if the user is the owner of that particular note. However, for some reason, the request is not being processed at all. The frontend is built using ...

What is the best way to utilize useEffect solely when the length of an array has

Is there a way to trigger a state update only when the length of the prop "columns" changes? useEffect(() => { if (columns.length !== prevColumns.length) { // update state } }, [columns]); Any suggestions on how to achieve this? ...

Ways to trigger a modal programmatically in the backend code?

My goal is to trigger the display of a modal when a button is clicked. The modal should be shown by clicking this button: <asp:Button ID="Button4" runat="server" class="btn btn-info" data-toggle="modal" OnClientClick="return false;" data-target="#View1 ...

Utilize the power of dual API integration in a single request (multi-scope capability)

While there may not be a definitive answer to this question, I want to ensure that my situation cannot be resolved in any way. The crux of my application (and consequently the issue) is that each user possesses their own unique database and does not have ...

Numerals for Central Leaflet Marker

Is there a way to effectively center numbers inside markers? Here is the current situation: View Marker with Number How to Create a Marker return L.divIcon({ className: "green-icon", iconSize: [25, 41], iconAnchor: [10, 44], popupAn ...

What are the best practices for implementing optional chaining in object data while using JavaScript?

In my current project, I am extracting singlePost data from Redux and converting it into an array using Object.keys method. The issue arises when the rendering process is ongoing because the singlePost data is received with a delay. As a result, the initi ...

Incorporating a Link into a Radio Button component in Material-UI using react-router

Greetings! I have two radio buttons and would like to include a link. I attempted to achieve this in the following manner: <RadioButton value="/searchByArtistAndName" label="Artist and Name" style={styles.radioButton} contai ...

Font family 'anticon' is not recognized

While following a coding tutorial on YouTube, I encountered an error message that has me stumped. Despite having the correct import statement and dependency installed, the issue persists. Error message in iOS simulator: https://i.stack.imgur.com/LOVCQl. ...

Issue with Material-UI Nested Checkbox causing parent DOM to not update upon selection changes

Currently, I am integrating a nested checkbox feature from a working example into my application. The functionality of the checkboxes covers seven different scenarios: - Scenario - No children, no parent selected - Select the parent -> select both pa ...

Ways to align the navigation icon to the left side

I need help positioning my help icon at the bottom of the screen, regardless of the user's monitor size. I've tried using margin and margin-top, but it doesn't adjust properly when changing monitor sizes. Any suggestions or assistance would ...

Swapping values between HTML tables and arrays with the power of JavaScript

I have a unique table structure that I need help with: My current table has 2 rows and multiple columns, but I want to change it to have 2 columns and multiple rows like this: To create the table, I am using two arrays named milestone and milestoneDate. ...

Looking for CSS templates for improving your business web apps?

Many CSS templates out there are fixed-width, typically around 900 pixels wide... Right now, I'm in the process of creating an intranet Rails application and I'm seeking a good resource for CSS templates designed specifically for business applic ...

Integrate React Material Table with Custom Navigation Buttons

Is it possible to incorporate First and Last page buttons into a MUI React Table? The current setup only includes previous and next page buttons. I'm looking for a unique solution like double arrow icons or something unconventional. https://i.stack.i ...

Adjust the size of H1, H2... tags based on their own specifications, rather than the surrounding element

I have run into a bit of a conundrum with my code and cannot seem to find the right solution. Here is what I currently have: <div id="bloquetexto4" class="bloquetexto"> <H2><b>TITULO</b></H2> <p>Texto bla bla bla.</p ...

`Considering various factors to alter class pairings`

I have defined a few style classes in my stylesheet as shown below: .left-align{ /* some styles here */ } .right-align{ /* some styles here */ } .validate-error{ /* some styles here */ } Depending on the type of data, I need to align the content ei ...