React- hiding div with hover effect not functioning as expected

I'm having trouble using the :hover feature in CSS to control the display of one div when hovering over another, it's not functioning as expected. I've successfully implemented this on other elements, but can't seem to get it right in this particular case. I must have made a mistake somewhere. Any guidance on what might be wrong would be greatly appreciated.

JSX

render() {
    return (
        <div className='row'>
            <div className='container-job' onClick={this.test}>
                <div className='row'>
                    <div className='job-title'>
                        {this.props.jobs_info.title}
                    </div>
                </div>
                <div className='row wrapper'>
                    <div className='category-title'>Category</div>
                    <div className='location-title'>Location</div>
                    <div className='type-title'>Type of Job</div>
                    <div className='creator-title'>Job Creator</div>
                </div>
                <div className='row wrapper'>
                    <div className='category'>
                        {this.props.jobs_info.job_team.title}
                    </div>
                    <div className='location'>
                        {this.props.jobs_info.job_location.title}
                    </div>
                    <div className='type'>
                        {this.props.jobs_info.job_work_type.title}
                    </div>
                    <div className='creator'>
                        {this.props.jobs_info.user.name}
                    </div>
                </div>
            </div>
            <div
                className='counter-container'
                id='counter-container'
                onMouseEnter={this.changeBackground}
                onMouseLeave={this.changeBackground2}
            >
                Candidates <br />
                {this.props.jobs_info.candidates_count}
            </div>

            <div className='delete-container-job center'>
                <ion-icon id='trash' name='trash'></ion-icon>
            </div>
        </div>
    );
}

CSS

.jobs-card {
    height: 100%;
    width: 100%;

    .container-job {
        position: relative;
        height: 100px;
        width: 860px;
        background-color: rgb(37, 45, 73);
        border-radius: 10px;
        margin-left: 30px;
        margin-bottom: 20px;
    }

    .container-job:hover {
        .delete-container-job {
            display: block !important;
        }
    }

    .job-title {
        position: relative;
        color: white;
        font-size: 16px;
        margin-left: 40px;
        margin-top: 15px;
        margin-bottom: 10px;
    }

    .row .wrapper {
        margin-left: 25px;
    }
    .counter-container {
        position: relative;
        background-color: rgb(37, 45, 73);
        border-radius: 10px;
        width: 110px;
        height: 100px;
        margin-left: 20px;
        text-align: center;
        color: white;
        font-size: 15px;
        padding-top: 30px;
    }

    .delete-container-job {
        position: relative;
        background-image: linear-gradient(to right, #4639a7, #78019c);
        height: 100px;
        width: 50px;
        right: 180px;
        border-top-right-radius: 10px;
        border-bottom-right-radius: 10px;
        display: none;
    }

    #trash {
        font-size: 22px;
        color: white;
        display: inline-block;
        margin-top: 40px;
    }

    .center {
        text-align: center;
    }

Answer №1

To effectively style the .delete-container-job element when hovering over .container-job, you must utilize the general sibling combinator.

.container-job:hover ~ .delete-container-job {
    display: block !important;
}

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

I am struggling to find the right way to center those images

Hello everyone, I'm currently attempting to set up the main content of the homepage resembling the image provided, but I'm encountering some challenges. Every approach I take seems to cause the image to overflow the container and occupy the enti ...

Conflicts arising between smoothState.js and other plugins

After successfully implementing the smoothState.js plugin on my website, I encountered an issue with another simple jQuery plugin. The plugin begins with: $(document).ready() Unfortunately, this plugin does not work unless I refresh the page. I have gone ...

What is the CSS method for determining the distance from the top of a container to the edge of the window?

I am working on a basic HTML layout that contains a few elements, including a scrollable div container located below them. Since the height of unknown-height is uncertain due to dynamic element generation, I need a simple method to enable scrolling in the ...

When using JSON.stringify(value, replacer), the output may vary between Chrome and Firefox

I'm encountering an issue when attempting to utilize JSON.stringify with the "replacer" function. var scriptTag = document.createElement('script'); scriptTag.type = 'text/javascript'; scriptTag.src = 'https:// ...

Inexplicably bizarre HTML glitch

I am currently utilizing a comment system that involves adding a new row to a SQL database. The system seems to be working fine; however, when I try to display the comments, the formatting of the comment div becomes all jumbled up. You can view the page wh ...

Utilizing Next.js to create a Higher Order Component (HOC) for fetching data from a REST API using Typescript is proving to be a challenge, as the

In my withUser.tsx file, I have implemented a higher order component that wraps authenticated pages. This HOC ensures that only users with a specified user role have access to the intended pages. import axios, { AxiosError } from "axios"; import ...

How can I retrieve the top-level key based on a value within a JSON object nested in JavaScript?

If I have the value Africola for key name in the following nested JSON structure, how can I retrieve its corresponding upper-level key 'barID1' using JavaScript? { "barID1": { "address": "4 East Terrace, Sydney NSW 2000", "appStoreURL" ...

Having trouble with Jquery not working, and I'm stumped trying to solve it

I wrote this function but I can't figure out why it's not working. The JS file is being loaded because other functions inside it are functioning properly, but those with this specific format aren't: $(function () { .... }); The intention ...

Retrieving the selected date from mat-datepicker into a FormControl

When creating a POST request to an API, I encountered an issue with the mat-datepicker field as it throws an error when inside the ngOnInit() call (since nothing is selected yet). Other fields like name, email, etc. work fine, but extracting a value from t ...

`I am unable to insert an image into PrimeReact`

I am struggling to integrate images into the dashboard using primereact. Despite placing my photo folder in the public directory and entering the correct photo path, the image is not displaying on the page. I have attempted numerous methods but have been ...

I am having difficulty modifying the value of 'margin-left' in my SCSS file when using React Bootstrap, even with the '!important' declaration. Can anyone help me understand why this is happening?

Before, I used the 'ml-auto' class in my navbar to make the dropdown align all the way to the left. But now, I want it to stay in place when the screen size shrinks and the navbar switches to vertical orientation. I attempted to apply a specific ...

managing nested JSON arrays in JavaScript

I have a straightforward task with handling a simple array that is divided into two parts: a group of vid_ids and a single element named page. Initially, I was iterating through the vid_id array using a for loop. However, upon adding the page element, I en ...

Delaying loops with JQuery Ajax

I am attempting to implement a delay in my AJAX data processing so that the loop runs a bit slower. Here's the code I'm working with: $(document).ready(function (){ $('#button').click(function(){ $('#hide').show ...

Divide a SINGLE BACKGROUND IMAGE in HTML into two separate links of equal size, one at the top and

As a beginner in HTML, I am trying to find a way to divide a background image into two equal sections without using image mapping. I attempted to split the links by setting the style to 0% and 50% to designate the top and bottom halves, but unfortunately, ...

What is the best way to prevent the table from being added again once it has been displayed?

I'm faced with the task of displaying an HTML table in a popup window when a button is clicked, using Bootstrap modal functionality. This scenario is similar to a preview function where user input is displayed in a table when a preview button is click ...

What is the best way to ensure that a specified number of list items (li) will align properly within the width of an unordered list (ul

I'm attempting to make all the li elements' width match that of my ul element. Here is the code I am using: http://jsfiddle.net/4XR5V/2/ I have looked at some similar questions on the website and tried adding: ul { width: 100%; display: tab ...

Scrolling text box utilizing Jquery

Currently, I am utilizing a scrolling box that functions well * view here * under normal circumstances. However, when there is an extensive amount of content below it, such as: <article class="content"> ...

Creating a div overlay triggered by the addition of a child tag

Using the Paypal zoid feature, I have a button that opens an iframe in the parent div when clicked. However, the iframe causes the other contents of the website to shift around, making it look messy. I'm wondering if there is a way to make the parent ...

The Map function is not functioning properly for a Next.js application that is relying on

I'm encountering an issue when attempting to display a simple JSX component based on Firebase data. When I try to return the component individually, it works perfectly fine. However, when I attempt to map over the data and display multiple components, ...

Is there a way for us to determine the time at which the user last took a screenshot or photo?

I am currently developing a website using Django and I have a unique requirement. I need to access the last image that a user has taken on their phone, without the image being shared by anyone else. The photo must be captured by the user's device itse ...