backgroundEver wondered how to create a shadow effect that inherits certain colors from the foreground element? Read this article to find out how! I was walking Pay attention to what's happening behind the TV. The colors displayed in the foreground of the TV screen are projected by the lamp as a colored shadow background. As the colors on the screen change, the background projection color also changes. Really cool, right? After seeing this, the first natural thought that came to my mind was, could I use Let’s get started! Make it happen As you will discover in the following paragraphs, creating smart colored shadows using only What you see is a picture of sushi Show pictures <div class="parent"> <div class="colorfulShadow sushi"></div> </div> We have a parent .sushi { margin: 100px; width: 150px; height: 150px; background-image: url("https://www.kirupa.com/icon/1f363.svg"); background-repeat: no-repeat; background-size: contain; } In the above style rules, we set Creating Shadows Now that we have our sushi
The above three functions are implemented by the following two style rules: .colorfulShadow { position: relative; } .colorfulShadow::after { content: ""; width: 100%; height: 100%; position: absolute; background: inherit; background-position: center center; filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.50)) blur(20px); z-index: -1; } Take a moment to walk through the implementation here, paying close attention to each property and its corresponding value. The most noteworthy are background: inherit; filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.50)) blur(20px); Our We have achieved a lot up to this point. For completeness, if you want your colorful shadows to animate as they scale in and out, here’s some extra .colorfulShadow { position: relative; } .colorfulShadow::after { content: ""; width: 100%; height: 100%; position: absolute; background: inherit; background-position: center center; filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.50)) blur(20px); z-index: -1; /* animation time! */ animation: oscillate 1s cubic-bezier(.17, .67, .45, 1.32) infinite alternate; } @keyframes oscillate { from { transform: scale(1, 1); } to { transform: scale(1.3, 1.3); } } If you want to enhance interactivity without looping animations, you can also use in conclusion Pseudo-elements allow us to use What if I want to apply a shadow like this to an empty element that isn't just an empty element with a background image? What if I have an This article is a translation. Please visit the original address: https://www.kirupa.com/html5/creating_colorful_smart_shadows.htm This is the end of this article about how to achieve colorful and smart shadows with CSS. For more relevant CSS shadow implementation content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Example of implementing bidirectional messaging between parent and child pages in HTML iframe
>>: Sample code for implementing a background gradient button using div+css3
environment Linux 3.10.0-693.el7.x86_64 Docker ve...
Table of contents Mysql master-slave synchronizat...
MySQL executes SQL through the process of SQL par...
Recently, the following effects need to be achiev...
As an entry-level Linux user, I have used simple ...
1. Execute SQL to view select @@session.sql_mode;...
Table of contents Overall Effect Listen for conta...
Recently, I need to implement a cascading selecti...
Basics 1. Use scaffolding to create a project and...
Nextcloud is an open source and free private clou...
This article introduces MySQL string interception...
I would like to ask a question. In Dreamweaver, I...
Angularjs loop object properties to achieve dynam...
A web server can build multiple web sites with in...
The main function of the brower module is to dete...