Comparison of CSS shadow effects: drop-Shadow and box-Shadow

Comparison of CSS shadow effects: drop-Shadow and box-Shadow

Drop-shadow and box-shadow are both CSS properties for shadow effects (halo effects). The biggest difference between the two is that box-shadow can only create rectangular shadows, while drop-shadow can create shadows of exactly the same shape as the opaque area of ​​the object. Here are the usage of two CSS properties:

.drop-shadow {
    -webkit-filter: drop-shadow(12px 12px 7px rgba(0, 0, 0, 0.7));
    filter: drop-shadow(12px 12px 7px rgba(0, 0, 0, 0.7))
}

.box-shadow {
    box-shadow: 12px 12px 7px rgba(0, 0, 0, 0.7);
}

Because both are shadow effects (halo effects), the parameters (values) that can be set for the two are almost the same: Taking the example above, all the parameter values ​​represent from left to right: horizontal offset, vertical offset, shadow blur distance, shadow color.

Next, we will further compare drop-shadow and box-shadow for you

Border and Transform Effects

The shadows of drop-shadow and box-shadow can both reflect the rounded corners and deformation effects of the border. The difference is: drop-shadow reflects the shape of the actual border, a solid frame has a solid shadow, and a dotted frame has a dotted shadow; box-shadow treats the border and the content inside as a complete square and creates a shadow of the entire square, while the border style will be ignored and it is directly treated as a solid frame.

.box {
    border: 5px solid #262b57;
    width: 120px;
    height: 120px;
    border-radius: 10px;
    transform: rotate(15deg);
    font-size: 40px;
    text-align: center;
    line-height: 120px;
}

.dashed {
    border-style: dashed;
}

Background and transparency

If the box has a set color (not transparent), the shadow effects of drop-shadow and box-shadow will look similar. What if the background of the block is semi-transparent? We can see from the picture that the color around the shadow is darker and the color in the middle is lighter, so we can infer that transparency will affect drop-shadow but not box-shadow.

.bk {
    background-color: #ffcc66;
}

.bk-alpha {
    background-color: rgba(255, 204, 102, 0.3);
}

Image border

From the example, we know that drop-shadow can reflect the irregular shape of image-border, while box-shadow treats the border directly as a solid frame and ignores the shape of the border image. The owl in the picture is a transparent PNG file. The drop-shadow not only reflects the shape of the border image, but also the shape of the owl inside the border. The box-shadow adheres to the consistent principle and treats the border and the picture as a complete square.

.frame {
    width: 286px;
    height: 240px;
    -moz-border-image: url(frame_green_.png) 25 25 repeat;
    -webkit-border-image: url(frame_green_.png) 25 25 repeat;
    border-width: 25px;
    border-image: url(frame_green_.png) 25 25 repeat;
    border-color: #79b218;
    border-style: inset;
    border-width: 25px;
    box-sizing: border-box;
    display: block;
    margin: 10px;
}

Pseudo-elements

The pseudo-element drop-shadow can reflect the shape of the pseudo-element, while the box-shadow will ignore the pseudo-element.

.addition {
    width: 100px;
    height: 100px;
    background-color: #ffcc66;
    margin: 10px 60px;
    position: relative;
    display: inline-block;
}

.addition:before {
    width: 50px;
    height: 50px;
    background-color: #ff8833;
    content: '';
    display: block;
    position: absolute;
    left: 0;
    top: 50%;
    margin-left: -40px;
    transform: rotate(45deg);
    margin-top: -10px;
}

.addition:after {
    width: 60px;
    height: 60px;
    background-color: #ff8833;
    margin: 10px;
    content: '';
    display: block;
    transform: rotate(20deg);
    transform: skew(20deg, 20deg);
    top: 5px;
    right: -40px;
    position: absolute;
}

Small blocks within a block

The shadow of drop-shadow can reflect the shape of all elements in the block, while box-shadow directly reflects the rectangular shadow of the block.

.square {
    width: 50px;
    height: 50px;
    display: inline-block;
    background-color: #ffcc66;
    margin: 20px;
}
.circle {
    width: 50px;
    height: 50px;
    display: inline-block;
    border-radius: 50%;
    background-color: #ff8833;
    margin: 20px;
}
<div class="demo-wrap">
    <div class="drop-shadow">
        <span class="square"></span>
        <span class="circle"></span>
        <p>drop-shadow</p>
    </div>
    <div class="box-shadow">
        <span class="square"></span>
        <span class="circle"></span>
        <p>box-shadow</p>
    </div>
</div>

Differences between drop-shadow and box-shadow

Drop-shadow does not have the internal border (inset shadow) and distance (spread) characteristics. As far as support is concerned, IE currently does not support the drop-shadow property; while all browsers generally support box-shadow.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Docker-compose creates a bridge, adds a subnet, and deletes a network card

>>:  Three steps to solve the IE address bar ICON display problem

Recommend

Example of how to increase swap in CentOS7 system

Preface Swap is a special file (or partition) loc...

Implementation of single process control of Linux C background service program

introduce Usually a background server program mus...

Solution to mysql ERROR 1045 (28000) problem

I encountered mysql ERROR 1045 and spent a long t...

Can asynchrony in JavaScript save await?

I knew before that to synchronously obtain the re...

About Zabbix forget admin login password reset password

The problem of resetting the password for Zabbix ...

How to run postgreSQL with docker

1. Install Docker. Reference URL: Docker Getting ...

Example of how to optimize MySQL insert performance

MySQL Performance Optimization MySQL performance ...

Responsive Web Design Learning (2) — Can videos be made responsive?

Previous episode review: Yesterday we talked abou...

Solution to the ineffective global style of the mini program custom component

Table of contents Too long to read Component styl...

Before making a web page, let’s take a look at these so-called specifications

This article has compiled some so-called specific...

Detailed installation process of MySQL 8.0 Windows zip package version

The installation process of MySQL 8.0 Windows zip...

Detailed explanation of 7 SSH command usages in Linux that you don’t know

A system administrator may manage multiple server...