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

HTML insert image example (html add image)

Inserting images into HTML requires HTML tags to ...

Several common methods for passing additional parameters when submitting a form

When submitting a form, you may encounter situatio...

MySQL Series 14 MySQL High Availability Implementation

1. MHA ​By monitoring the master node, automatic ...

javascript implements web version of pinball game

The web pinball game implemented using javeScript...

Solution to the error in compiling LVGL emulator on Linux

Table of contents 1. Error phenomenon 2. Error An...

Explanation of the basic syntax of Mysql database stored procedures

drop procedure sp_name// Before this, I have told...

Vue.js framework implements shopping cart function

This article shares the specific code of Vue.js f...

JavaScript Objects (details)

Table of contents JavaScript Objects 1. Definitio...

How to implement scheduled automatic backup of MySQL under CentOS7

The happiest thing that happens in a production e...

Share the 15 best HTML/CSS design and development frameworks

Professional web design is complex and time-consu...

js drag and drop table to realize content calculation

This article example shares the specific code of ...

Tomcat components illustrate the architectural evolution of a web server

1. Who is tomcat? 2. What can tomcat do? Tomcat i...