Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add image as box shadow with css?

Is it possible to add image as box shadow, for example to put image with dots instead of standard shadow?

https://i.stack.imgur.com/DOJGh.png

or somehow to replace shadow from picture with dots?

to get effect like this on picture down here

http://prntscr.com/fvjnht

like image 689
Armin Avatar asked Jul 14 '17 07:07

Armin


People also ask

Can you add a box shadow to an image CSS?

TL;DR — CSS offers two separate properties for adding shadows to text and other elements such as images: text-shadow and box-shadow.

How do I add a background image to a shadow in CSS?

Using box-shadow gives us a rectangular shadow, even though the element has no background, while drop-shadow creates a shadow of the non-transparent parts of the image. This will work whether the image is inline in the HTML (either as an inline SVG, or in <img> tag), or a CSS background image.


1 Answers

Did you want something like this? It's not exactly box-shadow, but it imitates it. You can set whatever image you like as a background for .image::after.

html, body {
  margin: 0;
}
body {
  width: 100vw;
  height: 100vh;
}
.contain {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.image{
  position: relative;
  width: 200px;
  height: 200px;
  background-image: url(http://via.placeholder.com/200x200);
}
.image::after {
  content: '';
  background: linear-gradient(to bottom, #333, red);
  position: absolute;
  width: 100%;
  height: 100%;
  bottom: -10px;
  right: -10px;
  z-index: -1;
}
<div class="contain">
  <div class="image"></div>
</div>
like image 99
fen1x Avatar answered Oct 05 '22 11:10

fen1x