简体   繁体   English

React- hover 隐藏 div 的效果不起作用

[英]React- hover effect to hide div doesn't work

I am trying to use:hover in css to show/hide the display of one of my divs when I hover over another div, but for some reason it's not working.我正在尝试使用:css 中的 hover 来显示/隐藏我的一个 div 的显示,当我 hover 在另一个 div 上时,但由于某种原因它不起作用。 I got it to work on other components but for some reason it's not working for this instance.我让它在其他组件上工作,但由于某种原因它不适用于这个实例。 Can't figure out what I did wrong.无法弄清楚我做错了什么。 please let me know what I'm doing wrong so I can fix my mistake请让我知道我做错了什么,这样我就可以解决我的错误

JSX 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 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;
    }

You need to use general sibling combinator to apply a style on .delete-container-job when .container-job is hovered on..container-job悬停在上面时,您需要使用通用兄弟组合器在.delete-container-job上应用样式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM