25 CSS Hacks Every Developer Should Know

Overlays

Problem: adding an overlay to an image.

Solution: use `::after` psendo-element.

.image-overlay {
  position: relative;
}
.image-overlay::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* black with 50% opacity */
}