Home Web Front-end CSS Tutorial Implementation of css3 visual effects

Implementation of css3 visual effects

Mar 22, 2018 pm 02:02 PM
css css3

This time I will bring you the implementation of css3 visual special effects. What are the precautions for realizing css3 visual special effects? The following is a practical case, let’s take a look.

1. Single-sided shadow

1. Application of box-shadow attribute, format: h-shadow v-shadow blur spread color inset attribute value introduction h- sahdow: The position of the horizontal shadow, negative values ​​are allowed

①v-shadow: The position of the vertical shadow, negative values ​​are allowed

②blur: Blur distance

③spread: The size of the shadow, Expansion distance, can be a negative number

④color: the color of the shadow

⑤inset/outset: internal or external shadow

2. The expansion distance of the shadow is valid for all four sides and cannot be used alone Applies to one side.

3. box-shadow supports settings for multiple sets of values ​​to take effect at the same time

Sample code:

.wrap{
            width: 200px;
            height: 120px;
            background: yellowgreen;
            box-shadow: 2px 0px 4px -2px black,
                        -2px 0px 4px -2px black;
        }
Copy after login

2. No Regular projection

1. The shape generated by border-radius is good with projection, but if pseudo elements and translucent decorations are added, the shadow performance will be very poor. The following situations will occur question.

① Semi-transparent image, Background image, or border-image

②The element sets a dotted, dotted or translucent border, but has no background (orbackground-clipWhen it is not border-box)

③The small corners inside the element are generated using pseudo elements

④The shape generated by clip-path

Solution: Use drop-shadow of svg to achieve

Sample code:

.wrap{
            width: 200px;
            height: 120px;
            border: 6px dotted yellowgreen;
            --box-shadow: 0px 0px 4px 0px black;
            -webkit-filter: drop-shadow(2px 0px 2px rgba(0,0,0,1))
        }
Copy after login

3. Chromosome effect

1. Based on filter implementation, apply the relevant values ​​​​of the filter attribute to adjust the saturation, brightness and other values ​​​​of the image

2. Based on min-blend-mode implementation, the role is to realize the element content and background and the following The elements are "mixed"

3. Basic background-blend-mode implementation, function: to realize the mixing of background color and background image, background image and image

Sample code for three situations:

.wrap1{
            width: 200px;
            height: 120px;
            overflow: hidden;
        }
        .wrap1 > img{
            max-height: 100%;
            max-width: 100%;
            -webkit-filter: sepia(1) saturate(4) hue-rotate(150deg);
        }
        .wrap2{
            width: 200px;
            height: 120px;
            background: hsl(335, 100%, 50%);
            overflow: hidden;
        }
        .wrap2 > img{
            height: 100%;
            width: 100%;
            mix-blend-mode: luminosity;
        }
        .wrap3{
            width: 200px;
            height: 120px;
            background-size: cover;
            background-color: hsl(335, 100%, 50%);
            background-image: url("../img/cat.png"); 
            background-blend-mode: luminosity;
        }
Copy after login

4. Frosted glass effect

Main implementation principle: the content pseudo-element background is the same picture as the underlying background; and plus filter:blur blur filter is enough. Note that blur cannot be applied to the underlying background, nor can it be applied to the background of the element (this will cause the element itself to be blurred, causing the text to be invisible), and can only be used on pseudo-elements.

The code is as follows:

body{
    background: url("../img/cat.png") no-repeat;
    background-size: cover;
}
.wrap{
    position: relative;
    width: 500px;
    margin: 0px auto;
    padding: 10px;
    line-height: 1.5;
    background: hsla(0, 0%, 100%, .3);
    overflow: hidden;
}
.wrap::before{
    content: '';
    background: url("../img/cat.png") 0/cover fixed;
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    filter: blur(20px);
    z-index: -1;
    margin: -30px;
}
Copy after login

Code description: 1. Both the body and wrap pseudo-elements apply the same background image

2. wrap The background-attachment is set to fixed, so that the background image does not move with the scrolling

3. The wrap pseudo-element is set to absolute positioning, and the z-index level is only higher than the background

4. Use blur to set the blur size of the wrap pseudo-element

5. Use negative margin values ​​to increase the width, and use overflow:hidden for the parent element to hide the overflow, making the blurred background more realistic.

5. Corner effect

Implementation steps

1. First use linear-gradient to achieve the corner effect 2, and then use linear-gradinet to generate it A triangle and set its position, width and height

The code is as follows:

.wrap{
        background: linear-gradient(to left bottom, transparent 50%, rgba(0, 0, 0, .4) 0) no-repeat 100% 0/2em 2em,
        linear-gradient(-135deg, transparent 1.4em, #58a 0);
        width: 200px;
        height: 120px;
    }
Copy after login

##Note

1 , 100% 0/2em 2em is positioning the position, width and height of the background element, especially the width and height of 2em are the normal width of the background element.

2. The 1.4em in the second linear-gradient is measured along the gradient axis, which is the distance from the gradient axis to the top edge of the element. In this example, it is the distance from the gradient axis to the top right edge

3. to left bottom means that the gradient starts from the lower left corner

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed graphic explanation of float in css

Four hiding methods in html+css

The above is the detailed content of Implementation of css3 visual effects. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles