Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to mix CSS inset shadows in a 50:50 proportion?

I would like to mix two inset box shadows. It should look like that, with a tiny smooth transition between:

enter image description here

I have tried to code it this way:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#button_one,
#button_two,
#button_three {
  font-family: Arial;
  padding: 20px;
  border-radius: 20px;
  border: 1px solid black;
  display: inline-block;
}

#button_one {
  box-shadow: 0 0 10px gray, inset 0 5px 5px red;
}

#button_two {
  box-shadow: 0 0 10px gray, inset 0 5px 5px blue;
}

#button_three {
  box-shadow: 0 0 10px gray, inset 0 5px 5px red, inset 0 5px 5px blue; /* What would be a solution here? */
}
<div id="button_one">Red Shadow Button</div> <!-- Looks good -->
<div id="button_two">Blue Shadow Button</div> <!-- Looks good -->
<div id="button_three">Red Blue Shadow Button</div> <!-- Looks bad! -->

Unfortunately, it doesn’t work the way like in the image. Additionally, there should be a normal gray box shadow like in the code example. Does anyone have an idea how to do that?

>Solution :

Use two pseudo element, one for each shadow then a mask to create the small fading effect in the middle

div[id] {
  font-family: Arial;
  padding: 20px;
  border-radius: 20px;
  border: 1px solid black;
  display: inline-block;
  position: relative;
  overflow:hidden;
}

div[id]:before,
div[id]:after {
  content: "";
  position: absolute;
  border-radius: inherit;
  inset: 0;
  box-shadow: inset 0 5px 5px var(--c, red);
  -webkit-mask: linear-gradient(var(--p, 90deg), #0000 45%, #000 55%);
  pointer-events: none;
}

div[id]:after {
  --c: blue;
  --p: -90deg;
}
<div id="button_one">Red Shadow Button</div>
<div id="button_two">Blue Shadow Button</div>
<div id="button_three">Red Blue Shadow Button</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading