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)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles