Filter blur css safari

filter

The filter CSS property applies graphical effects like blur or color shift to an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders.

Included in the CSS standard are several functions that achieve predefined effects. You can also reference an SVG filter with a URL to an SVG filter element.

Try it

Syntax

/* URL to SVG filter */ filter: url("filters.svg#filter-id"); /* values */ filter: blur(5px); filter: brightness(0.4); filter: contrast(200%); filter: drop-shadow(16px 16px 20px blue); filter: grayscale(50%); filter: hue-rotate(90deg); filter: invert(75%); filter: opacity(25%); filter: saturate(30%); filter: sepia(60%); /* Multiple filters */ filter: contrast(175%) brightness(3%); /* Use no filter */ filter: none; /* Global values */ filter: inherit; filter: initial; filter: revert; filter: revert-layer; filter: unset;

With a function, use the following:

filter: filter-function> [filter-function>]* | none 
filter: url(file.svg#filter-element-id)

Interpolation

When animated, if both the beginning and end filters have a function list of the same length without url() , each of their filter functions is interpolated according to its specific rules. If they have different lengths, the missing equivalent filter functions from the longer list are added to the end of the shorter list using their initial values, then all filter functions are interpolated according to their specific rules. If one filter is none , it is replaced with the filter functions list of the other one using the filter function default values, then all filter functions are interpolated according to their specific rules. Otherwise, discrete interpolation is used.

Functions

The filter property is specified as none or one or more of the functions listed below. If the parameter for any function is invalid, the function returns none . Except where noted, the functions that take a value expressed with a percent sign (as in 34% ) also accept the value expressed as decimal (as in 0.34 ).

When a filter property has two or more functions, its results are different from the same functions applied separately using multiple filter properties.

SVG filter

url()

Takes an URI pointing to an SVG filter, which may be embedded in an external XML file.

Filter functions

blur()

The blur() function applies a Gaussian blur to the input image. The value of radius defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. The initial value for interpolation is 0 . The parameter is specified as a CSS length, but does not accept percentage values.

svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> filter id="svgBlur" x="-5%" y="-5%" width="110%" height="110%"> feGaussianBlur in="SourceGraphic" stdDeviation="5"/> filter> svg> 

brightness()

The brightness() function applies a linear multiplier to the input image, making it appear more or less bright. A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged. Other values are linear multipliers on the effect. Values of an amount over 100% are allowed, providing brighter results. The initial value for interpolation is 1 .

svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> filter id="brightness"> feComponentTransfer> feFuncR type="linear" slope="[amount]"/> feFuncG type="linear" slope="[amount]"/> feFuncB type="linear" slope="[amount]"/> feComponentTransfer> filter> svg> 

contrast()

The contrast() function adjusts the contrast of the input image. A value of 0% will create an image that is completely gray. A value of 100% leaves the input unchanged. Values of an amount over 100% are allowed, providing results with more contrast. The initial value for interpolation is 1 .

svg style="position: absolute; top: -99999px" xmlns="http://www.w3.org/2000/svg"> filter id="contrast"> feComponentTransfer> feFuncR type="linear" slope="[amount]" intercept="-(0.5 * [amount]) + 0.5"/> feFuncG type="linear" slope="[amount]" intercept="-(0.5 * [amount]) + 0.5"/> feFuncB type="linear" slope="[amount]" intercept="-(0.5 * [amount]) + 0.5"/> feComponentTransfer> filter> svg> 

drop-shadow()

The drop-shadow() function applies a drop shadow effect to the input image. A drop shadow is effectively a blurred, offset version of the input image’s alpha mask drawn in a particular color, composited below the image. The function accepts a parameter of type (defined in CSS Backgrounds and Borders Module Level 3), with the exception that the inset keyword and spread parameter are not allowed. This function is similar to the more established box-shadow property; the difference is that with filters, some browsers provide hardware acceleration for better performance. The parameters of the parameter are as follows:

filter: drop-shadow(16px 16px 10px black)
svg style="position: absolute; top: -999999px" xmlns="http://www.w3.org/2000/svg"> filter id="drop-shadow"> feGaussianBlur in="SourceAlpha" stdDeviation="[radius]"/> feOffset dx="[offset-x]" dy="[offset-y]" result="offsetblur"/> feFlood flood-color="[color]"/> feComposite in2="offsetblur" operator="in"/> feMerge> feMergeNode/> feMergeNode in="SourceGraphic"/> feMerge> filter> svg> 

grayscale()

The grayscale() function converts the input image to grayscale. The value of amount defines the proportion of the conversion. A value of 100% is completely grayscale. A value of 0% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. The initial value for interpolation is 0 .

hue-rotate()

The hue-rotate() function applies a hue rotation on the input image. The value of angle defines the number of degrees around the color circle the input samples will be adjusted. A value of 0deg leaves the input unchanged. The initial value for interpolation is 0 . Though there is no maximum value; the effect of values above 360deg wraps around.

svg style="position: absolute; top: -999999px" xmlns="http://www.w3.org/2000/svg"> filter id="svgHueRotate"> feColorMatrix type="hueRotate" values="90"/> filter> svg> 

invert()

The invert() function inverts the samples in the input image. The value of amount defines the proportion of the conversion. A value of 100% is completely inverted. A value of 0% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. The initial value for interpolation is 0 .

opacity()

The opacity() function applies transparency to the samples in the input image. The value of amount defines the proportion of the conversion. A value of 0% is completely transparent. A value of 100% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount. The initial value for interpolation is 1 . This function is similar to the more established opacity property; the difference is that with filters, some browsers provide hardware acceleration for better performance.

saturate()

The saturate() function saturates the input image. The value of amount defines the proportion of the conversion. A value of 0% is completely un-saturated. A value of 100% leaves the input unchanged. Other values are linear multipliers on the effect. Values of amount over 100% are allowed, providing super-saturated results. The initial value for interpolation is 1 .

sepia()

The sepia() function converts the input image to sepia. The value of amount defines the proportion of the conversion. A value of 100% is completely sepia. A value of 0% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. The initial value for interpolation is 0 .

Combining functions

You may combine any number of functions to manipulate the rendering. The following example enhances the contrast and brightness of the image:

filter: contrast(175%) brightness(103%)

Formal definition

Initial value none
Applies to all elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
Inherited no
Computed value as specified
Animation type a filter function list

Formal syntax

filter = none | list> list> = [ function> | url> ]+ filter-function> = blur( )> | brightness( )> | contrast( )> | drop-shadow( )> | grayscale( )> | hue-rotate( )> | invert( )> | opacity( )> | sepia( )> | saturate( )> blur( )> = blur( ? ) brightness( )> = brightness( ? ) contrast( )> = contrast( ? ) drop-shadow( )> = drop-shadow( [ ? && 2,3> ] ) grayscale( )> = grayscale( ? ) hue-rotate( )> = hue-rotate( [ | ]? ) invert( )> = invert( ? ) opacity( )> = opacity( ? ) sepia( )> = sepia( ? ) saturate( )> = saturate( ? ) 

Examples

Applying filter functions

Examples of using the predefined functions are shown below. See each function for a specific example.

.mydiv < filter: grayscale(50%); > /* Gray all images by 50% and blur by 10px */ img < filter: grayscale(0.5) blur(10px); >

Applying SVG filters

Examples of using the URL function with an SVG resource are as follows:

.target < filter: url(#c1); > .mydiv < filter: url(commonfilters.xml#large-blur); >

Specifications

Browser compatibility

In Chrome 18 to 19, the saturate() function only takes integers instead of decimal or percentage values. From Chrome 20, this bug is fixed.

Internet Explorer 4 to 9 implemented a non-standard filter property. The syntax was completely different from this one and is not documented here.

Источник

CSS свойство filter. Фильтры в CSS

Internet Explorer c 4 до 10 версии поддерживает другое нестандартное свойство filter с тем же именем, но другим синтаксисом.

Chrome, Opera и Safari поддерживают свойство -webkit-filter.

Краткая информация по CSS-свойству filter

Правила написания свойства filter

Здесь none — отменяет действие наложенных фильтров, — применяемый фильтр. Перечислим имеющиеся в нашем распоряжении фильтры:

  • blur(px) Применяет эффект размытия к изображению. Большее значение будет создавать большее размытия. Если значение не указано, используется 0.
  • brightness(%) Регулировка яркости изображения. 0% сделает изображение полностью черным. 100% — дефолтное значение и представляет собой исходное изображение. Значение более 100% сделает изображение ярче.
  • contrast(%) Регулировка яркости изображения. 0% сделает изображение полностью черным. 100% — дефолтное значение и представляет собой исходное изображение. Значение более 100% сделает изображение более контрастным.
  • drop-shadow(x y размытие растяжение цвет) Добавляет тень к элементу, аналогичен CSS свойству box-shadow. Поясним значения параметров: x, y — обязательные значения, отвечает за смещение тени по горизонтали/вертикали относительно элемента. Положительная величина задает сдвиг тени вправо/вниз, отрицательная — влево/вверх соответственно. размытие — третий (необязательный) параметр, задается в пикселях. Добавляет эффект размытия тени. Большее значение будет создавать большее размытие (тень становится больше и светлее). Отрицательные значения не допускаются. Если не указано значение, используется 0 (края тени четкие). растяжение — необязательный параметр, измеряется в пикселях. Положительное значение заставит тень расширяться, а отрицательное — сжиматься. Если не указано, то будет 0 (тень будет иметь тот же размер, как элемент). цвет — необязательный параметр, отвечает за цвет тени. Если не указано, цвет зависит от браузера (часто черного цвета). В качестве примера создадим тень красного цвета, которая будет по 8 пикселей в толщину по горизонтали и по вертикали, с размытием, равным 10px:
filter: drop-shadow(8px 8px 10px red);
filter: url(svg-url#element-id)

Объектная модель

Объект.style.filter Объект.style.webkitFilter

Пример применения стиля filter

filter: none;

Источник

Читайте также:  Java remove all from set
Оцените статью