1

I have a project where I need to create a certain type of card. These cards contain a gradient background when hovered over. I have added a before item that is shown when the item is hovered over. In order to contain the background gradient within the card I have added a clip path attribute to the card.

But the problem I am facing is that the clip path doesn't clip the rounded border border-radius: 0.5rem;. I have searched and found that it is possible by using a polygon to clip path.

I have found a link where you can generate poly items to clip to: Clip poly generator.

But i cannot find a perfect polygon that fits. The circle is to rounded and the bevel item only has sharp borders.

body{
  background-color: black;
  }

.card-oval-gradient {
  position: relative;
  width: 10rem;
  height: 6rem;
  background-color: blue;
  border-radius: 0.5rem;
  clip-path: inset(0);
}

.card-oval-gradient > * {
  position: relative;
  z-index: 2;
}

.card-oval-gradient:hover::before {
  content: '';

  position: absolute;
  left: -7rem;
  top: -10rem;
  width: 18rem;
  height: 28rem;
  -moz-border-radius: 15rem / 20rem;
  -webkit-border-radius: 15rem / 20rem;
  border-radius: 15rem / 20rem;
  opacity: 0.6;
  transform: scaleX(-1) rotate(61deg);
  background-image: linear-gradient(
    138deg,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );

  filter: blur(50px);
}
<div class="card-oval-gradient">
</div>

3
  • stackoverflow.com/questions/31765345/… Commented Mar 29, 2021 at 9:12
  • @AnthonyBeaumecker I have read this question. But I couldn't get it to work for my example. Commented Mar 29, 2021 at 9:13
  • I'm not sure I understand why you need a clip path at all. Do you have an image of the desired result? Commented Mar 29, 2021 at 9:15

1 Answer 1

1

Use mask not clip-path:

body{
  background-color: black;
  }

.card-oval-gradient {
  position: relative;
  width: 10rem;
  height: 6rem;
  background-color: blue;
  border-radius: 0.5rem;
  -webkit-mask: linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0);
}

.card-oval-gradient > * {
  position: relative;
  z-index: 2;
}

.card-oval-gradient:hover::before {
  content: '';

  position: absolute;
  left: -7rem;
  top: -10rem;
  width: 18rem;
  height: 28rem;
  -moz-border-radius: 15rem / 20rem;
  -webkit-border-radius: 15rem / 20rem;
  border-radius: 15rem / 20rem;
  opacity: 0.6;
  transform: scaleX(-1) rotate(61deg);
  background-image: linear-gradient(
    138deg,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );

  filter: blur(50px);
}
<div class="card-oval-gradient">
</div>

Sign up to request clarification or add additional context in comments.

Comments

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.