DEV Community

Nguyễn Hữu Hiếu
Nguyễn Hữu Hiếu

Posted on

css overlay: create an overlay with opacity without affecting content inside the overlay


  • Create an overlay with opacity => content inside it also opacity
  • Want to ignore opacity on content inside the overlay


<div class="wrapper">
  <div class="overlay overlay-black">
    <h2>Hi Jisoo</h2>
  <img src="" alt="testpic">
Enter fullscreen mode Exit fullscreen mode
.overlay {
  width: 100%;
  height: 100%;
  position: fixed;
  width: 100vw;
  height: 100vh;
  display: flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  display: none;

.overlay-black {
  // css for content inside overlay
  background: rgba(0,0,0,0.1);
  color: white !important;

.wrapper:hover .overlay-black {
  display: flex;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)