0

In following Next.js Component i want to add hover effects to the .itemCard and the button only. Those two must have diffent hover effects. (ex- itemcard will have a box-shadow effect and the button will have a backgroud color change). I have tried pinter-events:none in various ways but had no luck.

const Img = (props: imgProps) => {
  return (
    <div className={styles.itemCard}>
      <div className={styles.imagecontainer}>
        <div className={styles.imageOuter}>
          <img className={styles.imageItself} src={props.img} alt="" />
        </div>
          <div className={styles.details}>
            <h3 className={styles.titleCardHome}>{props.title}</h3>
            <p className={styles.description}>Lorem ipsum dolor sit amet consectetur.</p>
            <p className={styles.priceHome}>{props.price}</p>
            <button className={styles.btncartAdd}>Add to Cart</button>
          </div>
      </div>
    </div>
  );
};

Here is my janky CSS:

.itemCard {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    max-width: 20rem;
    min-width: 15rem;
    background-color: rgba(255, 255, 255, 0);
    border-radius: 5px;
    margin: 10px;
    transition: .3s;
    transition: transform 0.3s ease-in-out;
}

.imagecontainer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    max-width: 20rem;
    min-width: 15rem;
    background-color: rgb(234, 202, 117);
    border-radius: 5px;
    margin: 20px;
    transition: .3s;
    transition: transform 0.3s ease-in-out;
    box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.139);
}

.imagecontainer .imageOuter {
    max-height: 60%;
    min-height: 60%;
    width: 100%;
    background-color: antiquewhite;
}




.imagecontainer .imageOuter img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 5px 5px 0px 0px;
    pointer-events: none;
}

.itemCard :not(.btncartAdd):hover{
    transition: transform 0.3s ease-in-out;
    /* transform: scale(1.01); */
    transition: .3s;
    box-shadow: 0px 10px 17px rgba(0, 0, 0, 0.214);
}
.details :not(.btncartAdd) {
    pointer-events: none;
  }
.itemCard
.details {
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    flex-direction: column;
    margin: -50px 5px -30px 5px;
    background-color: rgb(254, 229, 160);
    box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.067);
    width: 100%;
    height: 8rem;
    border-radius: 5px;
    padding: 10px;
}

.details .btncartAdd {
    background-color: rgb(223, 84, 20);
    border: none;
    width: 100%;
    padding: 5px;
    margin-top: 10px;
    color: white;
    border-radius: 5px;
}


how to achieve this?

2
  • Why aren't you using the :hover CSS pseudo-class then? Commented Apr 24, 2023 at 16:36
  • When you say you want to have the hover effect 'only' on .itemCard - it seems to be that it will take effect wherever the user hovers on the card. Are you saying the problem is getting a different effect when they hover over the button - i.e. for it then not to look like a hover on the whole card? Commented Apr 24, 2023 at 18:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.