Css overlay for focusing on button

C0mpl3x

Is there a way in css to create and overlay with opacity 0.5 And create a class that when applied will somehow affect the overlay so the final result will look something like this? enter image description here

What I am looking for a way that the class would affect the overlay.

Rickard Elimää

I don't know how the rest of your page looks like, but you can use a pseudo-element (to get an offset) with box-shadow to punch a hole around an element, simply by adding a class to the element you want to highlight. Needs some fine adjustment, if you got other shapes than rectangles.

div {
  box-shadow: 0px 0px 10px 1px lightgrey;
  border-radius: 1rem;
  padding: 1rem;
}

button {
  background-color: blue;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 1rem;
  cursor: pointer;
}

.highlight {
  position: relative;
}

.highlight::before {
  --white-area: -25px;
  content: '';
  position: absolute;
  left:   var(--white-area);
  right:  var(--white-area);
  top:    var(--white-area);
  bottom: var(--white-area);
  box-shadow: 
    inset 0px 0px 10px 0px rgba(0, 0, 0, 0.5),
    0px 0px 0px 9999px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  
  border-radius: 2rem;
}
<div>
  <h3>Don't Have an Account?</h3>

  <button class="highlight">Create Your Account</button>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related