Creating a shadow effect within a CSS mask: A simple guide

Is it possible to create a shadow within an SVG mask cutout?

Here is the code snippet I am currently using

index.html

<div class="content">
    <section id="home-section">
    </section>
    ...
</div>

styles.css

#home-section {
    background: url(img/bg.png) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    -webkit-mask: url(img/mask.svg) center/contain no-repeat;
    -webkit-mask-size: auto;
}

This is the current output of my code https://i.sstatic.net/uQI6V.png

However, this is the desired result illustrated in Illustrator: https://i.sstatic.net/8lE7f.png

Here is the link to download the SVG file: https://drive.google.com/file/d/1O7nGJHeYkgw9Al9BojSVI7f8zKzv4fbu/view?usp=sharing

Answer №1

Utilizing the drop-shadow filter can be advantageous in this scenario, especially when combined with masking techniques such as the following:

.box {
    height:300px;
    background:url(https://picsum.photos/id/1072/800/600) center/cover;
   overflow:hidden;
}

.box div {
  filter:drop-shadow(0 0 5px black);
  height:100%;
}

.box div::before {
  content:"";
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background:lightblue;
  -webkit-mask:
   /* your mask here */
      url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 13 13"><text  x="0" y="12" font-family="Arial, Helvetica, sans-serif" >A</text></svg>') left/33% auto,
      url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 13 13"><text  x="0" y="12" font-family="Arial, Helvetica, sans-serif" >B</text></svg>') center/33% auto,
     linear-gradient(#fff 0 0) right 10% top 50%/30% 80%,
    /* end of your mask*/
    linear-gradient(#fff 0 0);
   -webkit-mask-composite:destination-out;
   mask-composite:exclude;
   -webkit-mask-repeat:no-repeat;
}
<div class="box">
  <div></div>
</div>

By incorporating a specific mask into your code snippet, you can achieve the desired effect:

.box {
    height:300px;
    background:url(https://picsum.photos/id/1072/800/600) center/cover;
   overflow:hidden;
}

.box div {
  filter:drop-shadow(0 0 5px black);
  height:100%;
}

.box div::before {
  content:"";
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background:lightblue;
  -webkit-mask:
    url('https://i.ibb.co/JspDMsM/thebirds-mask3.png') center/contain no-repeat,
    linear-gradient(#fff 0 0);
   -webkit-mask-composite:destination-out;
   mask-composite:exclude;
   -webkit-mask-repeat:no-repeat;
}
<div class="box">
  <div></div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to customize this JQuery and HTML code to be specific to each row?

https://i.sstatic.net/RwuMl.pngIn CB UserList, each row in the form appears multiple times representing different records. The below code is intended to display a submit button and modules for show/hide functionality separately for each record on the list. ...

What could be causing this JavaScript code not to run?

Help needed! I'm a student struggling to diagnose the issue in my code. Whenever I click the buttons, nothing happens at all. I've tried debugging by isolating each function, but still can't seem to figure it out. I've searched through ...

Scrape dynamic web data with JSOUP

Having trouble grabbing the price? I cannot seem to get any output for the price and its weight. I've attempted different methods, but nothing is working Document doc = Jsoup.connect("https://www.jakmall.com/tokocamzone/mi-travel-charger-20a-output- ...

Turn off images using Selenium Python

In order to speed up the process, I believe that disabling images, CSS, and JavaScript can help since Webdriver waits for the entire page to load before moving on. from selenium import webdriver from selenium.webdriver.firefox.firefox_profile import Firef ...

Tips on utilizing CSS selectors with jQuery?

Is there a way to use jQuery to call a function on a web page load that will set the text "Hello world!" on all labels with the CSS class "hello"? I'm curious to learn more about how this works. Can anyone provide some insight? ...

Creating a dropdown menu in Bootstrap 4 using JSON information

I am trying to create a dynamic drop-down menu using an input field with a drop-down button inside a form. Currently, I am attempting to populate the drop-down menu with static JSON data. However, I am encountering issues with getting it to function proper ...

Switch out mobile buttons with Bootstrap 3

I'm currently utilizing Bootstrap 3: <ul class="dropdown-menu btn-block"> <li><a href="#">Reason 1</a></li> <!-- for desktop --> <li><a href="#" class="visible-md visible-lg">Reason 2&l ...

"Enhance your design with a cutting-edge gradient button using CSS

While exploring gradient effects in CSS, I stumbled upon this unique button design. After extensive searching on the internet, I couldn't find a solution on how to recreate the same button effect using CSS. Is it possible to create it using CSS?Button ...

Optimal methods for organizing various perspectives on a one-page website

I am developing an application that incorporates AngularJS and Bootstrap. The current setup involves organizing various views using ng-show, allowing for view changes based on button interactions and the enablement/disabling of ng-show values. Within a si ...

Highcharts gauge removing unnecessary white borders

I have created a highchart gauge code that looks great on JSFiddle, but when I paste it into my website, the 'border' options (borderColor and borderWidth) don't seem to work. The browser automatically adds white borders to my series, toolti ...

Tips for designing a CSS Grid that features a maximum width for the main content and a minimum width for the sidebar

I'm attempting to design a two-column CSS grid with a main content area that has a maximum width of 800px and a sidebar that has a minimum width of 200px: https://codepen.io/dash/pen/gOmXqGr The grid needs to be responsive: The yellow sidebar should ...

Experiencing Challenges with JavaScript Implementation Within an HTML Document

Code: <!DOCTYPE html> <head> <script type="text/javascript" src="jquery-3.3.1.js"> </script> <script type="text/javascript"> $(function() { alert("Hello World"); }); </script> <meta charset ...

"Emphasizing the Html.ActionLink menu for improved user navigation and

Currently, I am facing an issue with my menu. I want to clear previously visited links while keeping the current one styled as a:visited in CSS. Although I have attempted to achieve this, unfortunately, the code is not functioning properly. Here is what I ...

Here's a unique version: "A guide on using jQuery to dynamically adjust the background color of table

I need some assistance with changing the background color of td elements based on the th class. Specifically, I want to target all td elements under the bots class in the HTML code provided below. <table border="1" class="CSSTableGenerator" id="myTab ...

Can you adjust the size of a container based on a breakpoint using a class name in Bootstrap 5?

I am currently working on styling a div using Bootstrap 5. I have a specific requirement where I want the container to have a width of 50 when the screen size is bigger than the medium breakpoint, and by default, it should have a width of 75. In Tailwind, ...

Remove the bottom border from the active tab by utilizing the <div> and <a> elements

I am facing an issue with a tabbed menu on my webpage. While the menu is functioning correctly, I am struggling to remove the bottom border from the active tab. You can view all of my test code here. While I have come across solutions using <ul> an ...

The dark mode class in Next.js/React does not take effect until a local change is made

I've been diving into a helpful tutorial on implementing dark mode toggle in my project. The tutorial uses react-toggle and can be found here. Everything seems to be working fine except for one issue that arises on the initial page load. When the bro ...

Guide to effortlessly convert SCSS to CSS using an automatic vendor prefixer

Is there a tool that can convert SCSS to CSS while automatically adding vendor prefixes? I've tried using node-sass with npm, which worked well, but it doesn't add prefixes like box-sing: border-box; or display: flex; properties. Note: I also tr ...

Creating a dynamic table in HTML using PHP

I seem to be facing an issue with my PHP code. Below is the snippet of the code I am working with: <?php $s=(" SELECT * FROM my_tbl"); $W=mysql_query($s); ?> <table> <tr> <td> <center><s ...

angularjs: hide div based on text entered in textfield

Is there a way to hide a div (with the class "card") until the user inputs text into the textfield in an AngularJS application? I believe the solution involves using ng-show, but I'm unsure of how to implement this functionality. Any assistance would ...