Table of Contents
Previous words
Syntax
Grayscale
saturation

CSS filters

Feb 23, 2017 am 10:06 AM

Previous words

CSS filter filter is used for operations such as blurring, sharpening, and discoloration of elements. It is usually applied to pictures, backgrounds, etc. This article will introduce in detail the CSS filter filter

Syntax

filter

Initial value: none

Applies to: All elements

Inheritance: None

Values: none | blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate () | invert() | opacity() | saturate() | sepia() | url()

Compatibility: IE browser and android4.3-browser does not support it, android4.4+ needs to be added -webkit-prefix

 [Note] Use spaces to separate multiple filters. Filters usually use percentages (such as: 75%), or they can also be expressed in decimals (such as: 0.75)

Grayscale

grayscale

By using grayscale, the image will be turned into gray. If the value is 100%, it will be completely converted to grayscale image. If the value is 0%, the image will not change. The default is 0

saturation

saturate

A value of 0% means the image is completely desaturated, and a value of 100% means the image has no change. Values ​​above 100% are allowed, indicating higher saturation. If the value is not set, the value defaults to 1


##Brown

sepia

 Use sepia to convert the image to sepia. A value of 100% is completely sepia, and a value of 0% leaves the image unchanged. If not set, the value defaults to 0

Hue

hue-rotate

  Apply hue to the image through hue-rotate Rotate. The "angle" value sets the angle of the color circle by which the image will be adjusted. If the value is 0deg, there will be no change in the image. If the value is not set, the default value is 0deg. Although this value has no maximum value, a value exceeding 360deg is equivalent to going around again

Invert

invert

 Invert the input image by invert. 100% means complete inversion, a value of 0% means no change in the image. If the value is not set, the value defaults to 0

Transparency

opacity

opacity represents the degree of transparency of the image. A value of 0% means complete transparency, a value of 100% means no change to the image. If the value is not set, the value defaults to 1. This function is very similar to the existing opacity attribute. The difference is that through filter, some browsers will provide hardware acceleration to improve performance

Brightness

brightness

 Make it look brighter or darker by adjusting the brightnessbrightness. If the value is 0%, the image will be completely black. If the value is 100%, there will be no change in the image. Values ​​above 100% are okay and the image will be brighter than before. If there is no set value, the default is 1

contrast

contrast

The contrast of the image contrast, the value is 0% If so, the image will be completely gray. The value is 100% and the image is unchanged. Values ​​can exceed 100%, meaning lower contrast will be used. If there is no set value, the default is 1

blur

blur##  Set Gaussian blur to the image through blur. The "radius" value sets the standard deviation of the Gaussian function, or how many pixels are blended together on the screen, so the larger the value, the blurrier it is. If no value is set, the default is 0; this parameter can set the css length value, but does not accept percentage values

Shadow

drop-shadow

• drop-shadow (h-shadow v-shadow blur spread color) is used to set a shadow effect on the image. Shadows are composited underneath the image and can be blurred, offset versions of the matte that can be painted in a specific color. The function accepts values ​​of type

(defined in the CSS3 context), except that the "inset" keyword is not allowed. This function is very similar to the existing box-shadow property; the difference is that through filters, some browsers provide hardware acceleration for better performance

The parameters are as follows: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;offset-x&gt;&lt;offset-y&gt;(必须)   这是设置阴影偏移量的两个&lt;length&gt;值。&lt;offset-x&gt;设定水平方向距离,&lt;offset-y&gt;设定垂直距离。如果两个值都是0,则阴影出现在元素正后面 &lt;blur-radius&gt;(可选)          这是第三个&lt;length&gt;值。值越大,越模糊,则阴影会变得更大更淡。不允许负值。若未设定,默认是0(则阴影的边界很锐利) &lt;spread-radius&gt;(可选)        这是第四个&lt;length&gt;值。正值会使阴影扩张和变大,负值会使阴影缩小。若未设定,默认是0(阴影会与元素一样大小) &lt;color&gt;(可选)                查看&lt;color&gt;该值可能的关键字和标记。若未设定,颜色值会应用color属性的值。另外,如果颜色值省略,WebKit中阴影是透明的</pre><div class="contentsignin">Copy after login</div></div>  Although drop-shadow does not support inner shadow, it can achieve the shadow of irregular images, while box-shadow cannot achieve it

 [Note] Details about box shadow Information moves here

<style>
body{background-color: gray;}
.box{width: 260px;margin: 20px; padding: 20px;background-color: #fff;position: relative;font-size: 24px;line-height: 40px;}
.cor{position: absolute;left: -29px; top:27px;border: 15px solid transparent;border-right-color: #fff;}
.box-shadow{box-shadow: 5px 5px 10px black;}
.drop-shadow{filter: drop-shadow(5px 5px 10px black);}
</style>

<p class="box box-shadow">
    <i class="cor"></i>
    box-shadow
</p>
<p class="box drop-shadow">
    <i class="cor"></i>
    filter: drop-shadow
</p>
Copy after login


For more CSS filters and related articles, please pay attention to 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)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

How to Create an Animated Countdown Timer With HTML, CSS and JavaScript How to Create an Animated Countdown Timer With HTML, CSS and JavaScript Apr 11, 2025 am 11:29 AM

Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

HTML Data Attributes Guide HTML Data Attributes Guide Apr 11, 2025 am 11:50 AM

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

How We Created a Static Site That Generates Tartan Patterns in SVG How We Created a Static Site That Generates Tartan Patterns in SVG Apr 09, 2025 am 11:29 AM

Tartan is a patterned cloth that’s typically associated with Scotland, particularly their fashionable kilts. On tartanify.com, we gathered over 5,000 tartan

How to Build Vue Components in a WordPress Theme How to Build Vue Components in a WordPress Theme Apr 11, 2025 am 11:03 AM

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

PHP is A-OK for Templating PHP is A-OK for Templating Apr 11, 2025 am 11:04 AM

PHP templating often gets a bad rap for facilitating subpar code — but that doesn&#039;t have to be the case. Let’s look at how PHP projects can enforce a basic

Programming Sass to Create Accessible Color Combinations Programming Sass to Create Accessible Color Combinations Apr 09, 2025 am 11:30 AM

We are always looking to make the web more accessible. Color contrast is just math, so Sass can help cover edge cases that designers might have missed.

See all articles