Home > Web Front-end > HTML Tutorial > CSS3实现Drop-shadow_html/css_WEB-ITnose

CSS3实现Drop-shadow_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:43:52
Original
1084 people have browsed it

We can achieve the cool Drop-shadow effect through box-shdow and transform in CSS3:

The implementation steps are recorded below.

DOM structure

We only need a div as the main body, and the shadow can be achieved with the help of pseudo elements: before and :after. So our DOM structure is very simple.

<div class="drop-shadow">drop shadow effect</div>
Copy after login

Add shadows

Add shadows to the two pseudo-elements. Do the left one for now and deal with the right shadow later.

.drop-shadow:before, .drop-shadow:after {   content: "";   position: absolute;   z-index: -1;   bottom: 15px;   left: 10px;   width: 50%;   height: 20%;   box-shadow: 0 15px 20px rgba(125, 125, 125, 0.8); }
Copy after login

Now, what we see is this:

Adjust the shadow

Next we use transform to rotate the angle of the shadow. , which looks more three-dimensional.

.drop-shadow:before, .drop-shadow:after {   content: "";   position: absolute;   z-index: -1;   bottom: 15px;   left: 10px;   width: 50%;   height: 20%;   box-shadow: 0 15px 20px rgba(125, 125, 125, 0.8);   transform: rotate(-5deg); }
Copy after login

In this way we have completed the production of one side:

Adjust the shadow

Next, we only need to move one of the shadows Just go to the right.

.drop-shadow:after {   right: 10px;   left: auto;   transform: rotate(5deg); }
Copy after login

In this way, the shadow on the left is flipped to the right, and you’re done:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template