Tips for designing box-shadows that mimic varying levels of depth

Imagine creating a design with two different layers of objects set against a background. The first layer should consist of objects casting large shadows, while the second layer should have smaller shadows.

But what happens when an object from the front layer overlaps one in the second? In that case, the overlapping object should cast a large shadow on the background but a smaller shadow on the second-layer object.

Check out this example:

https://i.sstatic.net/YgskJ.png

Is it possible to achieve this effect using CSS or perhaps SVG filters? Any creative ideas?

Answer №1

Enhance a shadow effect using a pseudo element:

div {
  height: 150px;
  padding-top: 50px;
  margin: 3em;
  width: 300px;
  box-shadow: 2px 2px 5px;
}
p {
  margin: 2em;
  position: relative;
  box-shadow: 2px 2px 5px;
  height: 50px;
  width: 500px;
  background: white;
}
p:before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 265px;/* set offset value accordingly */
  box-shadow: 5px 5px 5px #333;
  pointer-events:none; /* avoids interaction, negative z-index can be used as well */
}
<div>
  <p>
  </p>
</div>

Adjust size, margin, and padding with actual content for accurate display :)

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

I'm curious if there is a specific regex pattern that can be used for validating custom page ranges in JavaScript

I'm in need of a regular expression for page sequences that should match: 1 1, 4-5 1, 4-5, 8, 11, 13-14 but should not match: 1,,,, 1, 4-5- 1, 4--------2233-----,,,, I've experimented with the following patterns but they haven't been su ...

Linking jQuery UI tabs to tabs on a different pageWould you like assistance

I am facing a challenge that I need help with. For a school project, I have to create 8 pages of HTML, each with a template and a menu. The menu consists of tabs that are supposed to link to separate pages when clicked. However, the issue is that when I cl ...

Scanning barcode and Qrcode with Angular js HTML5 for seamless integration

Looking to scan Barcode and Qrcode on Android, iPhone, and iPad devices for a project that is built on AngularJS and HTML5 as a mobile website. The requirement is not to download any third-party native application on the device, ruling out the use of nati ...

Switch out HTML tags depending on attribute content

In my current project, I am looking to replace all instances of the vanilla <a> tag with a different tag (<router-link>). The challenge lies in applying certain conditions based on the value of the href attribute (for example, it should ignore ...

Input tag styled in a center-aligned word document format

My Desired Text Alignment: I want the text to be centered horizontally at the top of the input. Words should break after hitting the internal padding, similar to how document creation software like Google Docs works with center alignment. Current Alignme ...

Tips for highlighting the final word in the headline using an underline

I'm attempting to create a title style similar to what is shown below https://i.sstatic.net/Qao4g.png The issue I'm facing is achieving the underline effect. I tried using title:after but it didn't give me the exact result I'm looking ...

Revise the content within the table cell

Running the following code using server push: $('tr[name=' + device + ']').find("td[id='status']").text('STARTED'); When attempting to access the element's id, it returns the correct value. $('tr[name=& ...

What is the best way to design a trapezoid-shaped div with perfectly centered text?

I'm currently attempting to design a div element that resembles a trapezoid and would like to position text in its center. So far, I have successfully created a div with the top border shaped like a trapezoid. However, the text is centered within the ...

Dynamically instantiate a new JavaScript object from an existing class by using input from the DOM

How can I dynamically create a new object instance of a class in Javascript for HTML, where the name of the object is derived from an input element? For example... Let's say we have a class named myClass and an object instance named Chickens with a p ...

I'm puzzled as to why the '>' combinator is not functioning the way I anticipated. It seems I must now style elements individually instead of being able to style them together as I originally thought

Check out the fiddle and code snippet here: http://jsfiddle.net/ogr27cLa/4/ <div> <ul id="navigation"> <a href="http://www.google.com"><li> <p>one</p> <ul> <a href="http://www.bi ...

Creating a component that surpasses all others

I have a code snippet that contains styling information for two div elements. How can I ensure that my <div id="home"> appears below my <div id="navigate"? Any suggestions? #home { background-color: black; color: grey; text-align: c ...

Is it possible to extract data from a table by adjusting Javascript in the inspector tool? The page is only showing today's data, but I'm interested in retrieving historical data by going back

My Desired Action: I am interested in extracting data from the 2nd and 3rd tables on this page. However, the data displayed is specific to the current 'day'. I wish to access readings from September 1st and import them into a Google Sheet. Speci ...

Guide for creating a scroll-triggered rotation animation using only JavaScript

Looking to achieve a cool scroll effect with an image that rotates on the X-axis by a specific degree, such as 70deg. The goal is to have the image's rotateX value change to 0deg when it enters the viewport upon scrolling and revert back to 70deg whe ...

I encountered an issue while attempting to fetch table data, receiving the following error message: "Uncaught TypeError: result.rows.product is not a function at products.html:134."

https://i.sstatic.net/WZ5CC.pngHere is the HTML I have written <form> <br/> <label for="products1">Product Name:</label> <input type="text" name="pdt" id="pr ...

How to rotate text direction using JavaScript and CSS

Despite my extensive efforts, I have been unable to find a solution to a seemingly simple problem. In JavaScript, I have generated dynamic text using the following code: context.fillText('name', 10, 10, 20); Now, I need this text to be ori ...

Tips for creating a responsive website header

My header includes a navigation bar, logo, and a brief description. I'm struggling to make it responsive. The navbar is fine with the hamburger icon, but my solution doesn't match the visual graphic I want for smaller viewports. How can I achiev ...

What is the best way to manage the changing selection in a drop-down list?

Can someone help me with a coding issue I am facing? <select name="txtTK" > <option value="None">---</option> <option value="Mat">Materials</option> <option value="Cate">Category</option> <option ...

What are the HTML5 elements that include the "load event" within their onload attribute?

Mozilla's MDN provides information regarding the load Event with this brief explanation: The load event is triggered when a resource and its dependent resources have completed loading. and references standard 1, which states Trusted Targets: ...

associating the highlighted text with a specific attribute of the selectbox

Using my coding skills, I developed a small application that enables users to add text from a textarea to a div block. My goal is to prevent the appended text when the user clicks on the yellow div, and highlight the selected text properties (such as font ...

"Efficiently handle multiple instances of the same name using AJAX, JavaScript

I have a PHP-generated multiple form with HTML inputs containing IDs and NAMEs. I am struggling to capture all this information. When I click the "Done" button, everything is marked as completed due to the button names. <?$command = "SELECT * FROM exam ...