0

Is there a way to create inner shadow for geometric shapes with text inside, made with CSS?

That's what I need to create:
enter image description here

I used the code from this thread: Required pentagon shape with right direction CSS and HTML

If the shape made of a div and a triangle - I can to set inner shadow for the div only. But even if I could set shadow for the triangle too, a border between them will become visible.

div {
  position: relative;
  width: 125px;
  height: 150px;
  background: #4275FF;

  -moz-box-shadow: inset 0 0 10px #000000;
  -webkit-box-shadow: inset 0 0 10px #000000;
  box-shadow: inset 0 0 10px #000000;
}
div:after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-top: 75px solid transparent;
  border-bottom: 75px solid transparent;
  border-left: 25px solid #4275FF;
  right: -25px;
}
<div></div>

If I use a swg, I can create an inner shadow using box-shadow, but the triangle part of the form will not cast shadow. And also in this case, to change the proportions of this shape is not very convenient.

div {
  width: 150px;
  height: 150px;
  background: #4275FF;
  
    -moz-box-shadow: inset 0 0 10px #000000;
        -webkit-box-shadow: inset 0 0 10px #000000;
        box-shadow: inset 0 0 10px #000000;
}
<svg width="150" height="150">
  <defs>
    <clipPath id="shape">
      <path d="M0,0 h125 l25,75 l-25,75 h-125z" />
    </clipPath>
  </defs>
  <foreignObject clip-path="url(#shape)" width="100%" height="100%">
    <div></div>
  </foreignObject>
</svg>
Community
  • 1
  • 1
Rumata
  • 1,027
  • 3
  • 16
  • 47

1 Answers1

1

Since box-shadow can only be applied either on one side or all of them, I tried to get it with multiple backgrounds.

You can change the values to get the appropriate size for you.

.pentagon {
  background: linear-gradient(to right,black -3px, transparent 7px),
  linear-gradient( black -3px, transparent 7px),
  linear-gradient(to top , black -3px, transparent 7px),
  #4275FF;
  
  width: 200px;
  height: 200px;
  position: relative;
  /* box-shadow: inset 0 0 10px #000000; */
  z-index: 10; /* put it higher in the stacking order */
  
  padding: 15px;
  box-sizing: border-box;
}

.pentagon::before {
  content: '';
  position: absolute;
  width: 140px;
  height: 20px;
  top: 47px;
  right: -112px;
  background: linear-gradient(black -4px, transparent 7px);
  transform: rotate(45deg);
  z-index: 2;
}

.pentagon::after {
  content: "";
  position: absolute;
  bottom: 47px;
  width: 140px;
  height: 20px;
  right: -112px;
  background: linear-gradient(black -4px, transparent 7px);
  transform: rotate(135deg);
  z-index: 2;
}

.pentagon-pointer {
  display: block;
  position: absolute;
  top: 0;
  right: -98px;
  border-left: 98px solid #4275FF;
  border-bottom: 100px solid transparent;
  border-top: 100px solid transparent;
  z-index: 1;
}
<div class="pentagon">
<div class="content">
  PUT YOUR CONTENT HERE
</div>
<div class="pentagon-pointer"></div>
</div>

Here's a JSfiddle to try as well.

pol
  • 2,641
  • 10
  • 16