


How to use CSS to achieve the surface shadow effect sample code sharing
I don’t know what you will do when you encounter a very gorgeous design drawing when working on a project. Some design drawings often use shadow effects to make them look more three-dimensional. Generally, lazy people like me just cut out the drawings. I didn't even think about studying how to implement the code.
Later on, our design drafts were constantly being revised and revised. *** was really annoying me to death. If he changed the drawings, I would cut them out and replace them with the original ones. So I decided to study this thing. In fact, we can achieve it!
As shown in the picture:
The above effect is the most typical effect of daily writing projects. Friends who do design must know that PS can do it in minutes , but can we also implement it in code? ——Tell them: It must be possible! Haha o(∩_∩)o; If you are talking big words, then you should put some effort into research!
Part One: HTML
The content of the page part is very simple. Next, let us look at the CSS part.
<p class="con yy"> <h1 id="曲线阴影">曲线阴影</h1></p><ul class="box"> <li><img src="/static/imghwm/default1.png" data-src="img/1.jpg" class="lazy" alt="How to use CSS to achieve the surface shadow effect sample code sharing" ></li> <li><img src="/static/imghwm/default1.png" data-src="img/2.jpg" class="lazy" alt="How to use CSS to achieve the surface shadow effect sample code sharing" ></li> <li><img src="/static/imghwm/default1.png" data-src="img/3.jpg" class="lazy" alt="How to use CSS to achieve the surface shadow effect sample code sharing" ></li></ul>
Part 2: CSS3
When we see the picture above, everyone’s first impression must be CSS3 box-shadow ,But if it’s just like this, can we achieve it? It's clear not.
Whether it is a curved surface or a warped edge, box-shadow cannot be realized by itself. We need to cooperate with CSS3's pseudo-class element to achieve it.
Let’s take a look at the code!
We can implement surface shading with the following code. Friends who are not familiar with pseudo-class elements can check the documentation by themselves.
*{ padding: 0; margin: 0; list-style: none;}.con{ width: 70%; height: 200px; margin: 50px auto; background:#FFFFFF; line-height: 200px; text-align: center; font-size: 24px; }.yy{ position: relative; box-shadow: 0 1px 4px rgba(0,0,0,0.3), 0 0 40px rgba(0,0,0,0.1) inset; -webkit-box-shadow:0 1px 4px rgba(0,0,0,0.3), 0 0 40px rgba(0,0,0,0.1) inset; -moz-box-shadow:0 1px 4px rgba(0,0,0,0.3), 0 0 40px rgba(0,0,0,0.1) inset; -o-box-shadow: 0 1px 4px rgba(0,0,0,0.3), 0 0 40px rgba(0,0,0,0.1) inset; }.yy:after , .yy:before{ position: absolute; content: ''; top: 50%; bottom: -1px; left: 10px; right: 10px; background:#fff; z-index: -1; /* 圆角水平为100px 垂直为10px 必须用‘/’分开 ,不可以为空格 */ border-radius: 100px/10px; box-shadow: 0 0 20px rgba(0,0,0,0.3); -webkit-box-shadow: 0 0 20px rgba(0,0,0,0.3); -moz-box-shadow: 0 0 20px rgba(0,0,0,0.3); -o-box-shadow: 0 0 20px rgba(0,0,0,0.3); }
The following code is how to achieve the effect of warping shadow:
.box{ width: 980px; height: 300px; margin: 0 auto; }.box li img{ display: block; width: 290px; height: 200px; }.box li{ position: relative; float: left; width: 290px; height: 200px; background: #FFFFFF; padding: 5px; margin-right: 25px; box-shadow: 0 0px 4px rgba(0,0,0,0.3) , 0 0 60px rgba(0,0,0,0.1) inset; -moz-box-shadow: 0 0px 4px rgba(0,0,0,0.3) , 0 0 60px rgba(0,0,0,0.1) inset; -webkit-box-shadow: 0 0px 4px rgba(0,0,0,0.3) , 0 0 60px rgba(0,0,0,0.1) inset; -o-box-shadow: 0 0px 4px rgba(0,0,0,0.3) , 0 0 60px rgba(0,0,0,0.1) inset; }.box li:before{ position:absolute; content: ''; width: 90%; height: 80%; left: 18px; bottom: 11px; z-index: -2; background: transparent; box-shadow: 0 8px 20px rgba(0,0,0,0.6); -moz-box-shadow: 0 8px 20px rgba(0,0,0,0.6); -webkit-box-shadow: 0 8px 20px rgba(0,0,0,0.6); -o-box-shadow: 0 8px 20px rgba(0,0,0,0.6); transform: skew(-12deg) rotate(-5deg); -moz-transform: skew(-12deg) rotate(-5deg); -webkit-transform: skew(-12deg) rotate(-5deg); -o-transform: skew(-12deg) rotate(-5deg); }.box li:after{ position:absolute; content: ''; width: 90%; height: 80%; right: 18px; bottom: 11px; z-index: -2; background: transparent; box-shadow: 0 8px 20px rgba(0,0,0,0.6); -moz-box-shadow: 0 8px 20px rgba(0,0,0,0.6); -webkit-box-shadow: 0 8px 20px rgba(0,0,0,0.6); -o-box-shadow: 0 8px 20px rgba(0,0,0,0.6); transform: skew(12deg) rotate(5deg); -moz-transform: skew(12deg) rotate(5deg); -webkit-transform: skew(12deg) rotate(5deg); -o-transform: skew(12deg) rotate(5deg); }
The above is the detailed content of How to use CSS to achieve the surface shadow effect sample code sharing. For more information, please follow other related articles on the PHP Chinese website!

The React ecosystem offers us a lot of libraries that all are focused on the interaction of drag and drop. We have react-dnd, react-beautiful-dnd,

There have been some wonderfully interconnected things about fast software lately.

I can't say I use background-clip all that often. I'd wager it's hardly ever used in day-to-day CSS work. But I was reminded of it in a post by Stefan Judis,

Animating with requestAnimationFrame should be easy, but if you haven’t read React’s documentation thoroughly then you will probably run into a few things

Perhaps the easiest way to offer that to the user is a link that targets an ID on the element. So like...

Listen, I am no GraphQL expert but I do enjoy working with it. The way it exposes data to me as a front-end developer is pretty cool. It's like a menu of

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

I've recently noticed an interesting change on CodePen: on hovering the pens on the homepage, there's a rectangle with rounded corners expanding in the back.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function