Solution 1 :

You have to chain both the not() pseudoclasses into a single selector if you want them to operate like a logical and :

&:hover:not(.order-item-cooked):not(.order-item-delivered)  .checkmark {
    background-color: #ccc;
}

Problem :

I am working on a ReactJS application and I have the following HTML code that is used in a component:

<div class="order-box">
    <div class="order-header">Table #1</div>
    <div class="order-list">
        <div class="order-item-container  ">
            <span class="checkmark"></span>
            <div class="order-item-name">Fish and Chips&nbsp;&nbsp;×&nbsp;&nbsp;1</div>
        </div>
        <div class="order-item-container  ">
            <span class="checkmark"></span>
            <div class="order-item-name">Teriyaki Chicken&nbsp;&nbsp;×&nbsp;&nbsp;1</div>
        </div>
        <div class="order-item-container  ">
            <span class="checkmark"></span>
            <div class="order-item-name">Satay Chicken&nbsp;&nbsp;×&nbsp;&nbsp;2</div>
        </div>
        <div class="order-item-container  ">
            <span class="checkmark"></span>
            <div class="order-item-name">Lava Cake&nbsp;&nbsp;×&nbsp;&nbsp;2</div>
        </div>
    </div>
</div>

I am using Sass to style the HTML code. I have the following Sass code:

.order-box {
    border: 1px solid #c3c9c8;
    height: 400px;
    width: 400px;
    border-radius: 5px;
    box-shadow: 0 10px 6px -6px #ededed;
    overflow: hidden;
}

.order-list {
    overflow-y: scroll;
    height: 80%;
}

.order-header {
    text-align: center;
    background: #222222;
    color: #ffffff;
    font-weight: bold;
    font-size: 26px;
    height: 20%;
    display: flex;
    justify-content: center;
    align-items: center;
}


.order-item-container {
    display: block;
    position: relative;
    padding-left: 35px;
    cursor: pointer;
    font-size: 22px;
    user-select: none;
    margin: 30px;

    &.order-item-cooked {
        .order-item-name {
            text-decoration: line-through;
        }

        .checkmark {
            background: #222222;

            &:after {
                display: block;
            }
        }
    }


    &.order-item-delivered {
        .order-item-name {
            text-decoration: line-through;
        }

        .checkmark {
            background: #222222;

            &:after {
                display: block;
            }
        }
    }


    &:hover:not(.order-item-cooked) .checkmark {
        background-color: #ccc;
    }


    &:hover:not(.order-item-delivered) .checkmark {
        background-color: #ccc;
    }

}

.checkmark {
    position: absolute;
    top: 2px;
    left: 0;
    height: 25px;
    width: 25px;
    border-radius: 15px;
    background-color: #eee;

    &:after {
        content: "";
        position: absolute;
        display: none;
        left: 9px;
        top: 5px;
        width: 5px;
        height: 10px;
        border: solid white;
        border-width: 0 3px 3px 0;
        transform: rotate(45deg);
    }
}

In my React code, depending on certain conditions, the classes "order-item-cooked" and "order-item-delivered" are added to the div with the class "order-item-container".

E.g. You can have either of the following:

<div class="order-item-container order-item-cooked">
<div class="order-item-container order-item-delivered">

When the div with the order-item-container class also has the "order-item-cooked" or the "order-item-delivered" class, if one hovers over the checkmark defined by the span tag inside that div, the background colour should not change to #ccc.

The following Sass code deals with this:

    &:hover:not(.order-item-cooked) .checkmark {
            background-color: #ccc;
        }


   &:hover:not(.order-item-delivered) .checkmark {
            background-color: #ccc;
        }

With the above in my Sass file, when I hover over a checkmark that is within a div that has either the order-item-cooked or the order-item-delivered class, the background colour changes to #ccc.

I am not sure why this is occurring. Any insights are appreciated.

By

Leave a Reply

Your email address will not be published. Required fields are marked *