Css прозрачность a filter

CSS фильтры

CSS3-свойство filter позволяет применить фильтры к элементам, с помощью них можно инвертировать цвета, осветлить или затемнить элементы, полное описание на developer.mozilla.org.

В данной статье представлены только основные фильтры по цвету, по мимо них есть наложение тени и фильтры с использованием SVG.

Blur – размытие

Размытие по Гауссу, значение задается в px или em, по умолчанию 0, отрицательные значения не допускается.

Brightness – яркость

Понижение или повышение яркости изображения, значение задается в процентах или числом. По умолчанию 100% или 1, отрицательное значение не допускается.

Contrast – контраст

Понижение или повышение контраста изображения, значение задается в процентах или числом, по умолчанию 100% или 1, отрицательное значение не допускается.

Grayscale – обесцвечивание

Обесцвечивание, значение от 0% до 100% или число от 0 до 1, отрицательное значение не допускается.

Hue-rotate – замена цветов

Замена цветов, в качестве значения указывается угол (deg) от 0 до 360, значение может быть отрицательным.

Invert – инверсия цветов

Инверсия цветов, значение от 0% до 100% или число от 0 до 1, отрицательное значение не допускается.

Opacity – прозрачность

Прозрачность элемента. Значение от 0% до 100% или от 0 до 1, по умолчанию 100%.

Saturate – насыщенность

Насыщенностью цветов, интенсивность задаётся положительным числом или процентами, по умолчанию 1 или 100%.

Sepia – сепия

Сепия или эффект старины, значение от 0% до 100%.

Комментарии

Другие публикации

Contenteditable – текстовый редактор

Если добавить атрибут contenteditable к элементу, его содержимое становится доступно для редактирования пользователю, а.

Источник

CSS filter Property

Tip: More «Try it Yourself» examples below.

Definition and Usage

The filter property defines visual effects (like blur and saturation) to an element (often ).

Default value: none
Inherited: no
Animatable: yes. Read about animatable Try it
Version: CSS3
JavaScript syntax: object.style.filter=»grayscale(100%)» Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Numbers followed by -webkit- specify the first version that worked with a prefix.

CSS Syntax

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

Tip: To use multiple filters, separate each filter with a space (See «More Examples» below).

Filter Functions

Note: The filters that use percentage values (i.e. 75%), also accept the value as decimal (i.e. 0.75).

Filter Description Demo
none Default value. Specifies no effects Demo ❯
blur(px) Applies a blur effect to the image. A larger value will create more blur.

Possible values:
h-shadow — Required. Specifies a pixel value for the horizontal shadow. Negative values place the shadow to the left of the image.

v-shadow — Required. Specifies a pixel value for the vertical shadow. Negative values place the shadow above the image.

blur — Optional. This is the third value, and must be in pixels. Adds a blur effect to the shadow. A larger value will create more blur (the shadow becomes bigger and lighter). Negative values are not allowed. If no value is specified, 0 is used (the shadow’s edge is sharp).

spread — Optional. This is the fourth value, and must be in pixels. Positive values will cause the shadow to expand and grow bigger, and negative values will cause the shadow to shrink. If not specified, it will be 0 (the shadow will be the same size as the element).
Note: Chrome, Safari and Opera, and maybe other browsers, do not support this 4th length; it will not render if added.

color — Optional. Adds a color to the shadow. If not specified, the color depends on the browser (often black).

An example of creating a red shadow, which is 8px big both horizontally and vertically, with a blur effect of 10px:

filter: drop-shadow(8px 8px 10px red);

0% (0) is default and represents the original image.
100% will make the image completely gray (used for black and white images).

0% (0) is default and represents the original image.
100% will make the image completely inverted.

0% is completely transparent.
100% (1) is default and represents the original image (no transparency).

0% (0) will make the image completely un-saturated.
100% is default and represents the original image.
Values over 100% provides super-saturated results.

0% (0) is default and represents the original image.
100% will make the image completely sepia.

More Examples

Blur Example

Apply a blur effect to the image:

Источник

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.

Several functions, such as blur() and contrast() , are available to help you achieve predefined effects.

Try it

Syntax

/* 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%); /* URL */ filter: url("filters.svg#filter-id"); /* Multiple filters */ filter: contrast(175%) brightness(3%); filter: drop-shadow(3px 3px red) sepia(100%) drop-shadow(-3px -3px blue); /* Use no filter */ filter: none; /* Global values */ filter: inherit; filter: initial; filter: revert; filter: revert-layer; filter: unset; 

With a function, use the following:

You can use url() to reference an SVG filter element. For a reference to an SVG element, use the following syntax:

filter: url(file.svg#filter-element-id); 

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 the filter property values contains multiple functions, the filters are applied in order.

Applies a Gaussian blur to the input image.

Applies a linear multiplier to the input image, making it appear more or less bright. Values are linear multipliers on the effect, with 0% creating a completely black image, 100% having no effect, and values over 100% brightening the image.

Adjusts the contrast of the input image. A value of 0% makes the image grey, 100% has no effect, and values over 100% create a contrast.

Applies the parameter as a drop shadow, following the contours of the image. The shadow syntax is similar to (defined in the CSS backgrounds and borders module), with the exception that the inset keyword and spread parameter are not allowed. As with all filter property values, any filters after the drop-shadow() are applied to the shadow.

filter: drop-shadow(16px 16px 10px black); 

Converts the image to grayscale. A value of 100% is completely grayscale. The initial value of 0% leaves the input unchanged. Values between 0% and 100% produce linear multipliers on the effect.

Applies a hue rotation. The value defines the number of degrees around the hue color circle at which the input samples will be adjusted. A value of 0deg leaves the input unchanged.

Inverts the samples in the input image. A value of 100% completely inverts the image. A value of 0% leaves the input unchanged. Values between 0% and 100% have linear multipliers on the effect.

Applies transparency. 0% makes the image completely transparent and 100% leaves the image unchanged.

Saturates the image, with 0% being completely unsaturated, 100% leaving the image unchanged, and values of over 100% increasing saturation.

Converts the image to sepia, with a value of 100% making the image completely sepia and 0% making no change.

Combining functions

You may combine any number of functions to manipulate the rendering. The filters are applied in the order declared. The following example enhances the contrast and brightness of the image:

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

Interpolation

When animated, if both the beginning and end filters have a function list of the same length without url() in the same order, each of their filter functions is interpolated according to the filter function’s specific rules.

If the filter lists are of different lengths, the missing equivalent filter functions from the longer list are added to the end of the shorter list. The added functions use their initial, no filter modification values. All the filters listed are then interpolated according to the filter function’s specific rules. Otherwise, discrete interpolation is used.

Formal definition

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

Formal syntax

filter =
none |

=
[ | ]+

=
|
|
|
|
|
|
|
|
|

=
url( * ) |
src( * )

=
blur( ? )

=
brightness( [ | ]? )

=
contrast( [ | ]? )

=
drop-shadow( [ ? && ] )

=
grayscale( [ | ]? )

=
hue-rotate( [ | ]? )

=
invert( [ | ]? )

=
opacity( [ | ]? )

=
sepia( [ | ]? )

=
saturate( [ | ]? )

Examples

Applying filter functions

The filter property is applied to the second image, greying and blurring both the image and its border.

img  border: 5px solid yellow; > /* Gray the second image by 40% and blur by 5px */ img:nth-of-type(2)  filter: grayscale(0.4) blur(5px); > 
img src="pencil.jpg" alt="Original image is sharp" /> img src="pencil.jpg" alt="The image and border are blurred and muted" /> 

Repeating filter functions

Filter functions are applied in order of appearance. The same filter function can be repeated.

#MDN-logo  border: 1px solid blue; filter: drop-shadow(5px 5px 0 red) hue-rotate(180deg) drop-shadow(5px 5px 0 red); > 
svg id="MDN-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 361 104.2" xml:space="preserve" role="img"> title>MDN Web Docstitle> path d="M197.6 73.2h-17.1v-5.5h3.8V51.9c0-3.7-.7-6.3-2.1-7.9-1.4-1.6-3.3-2.3-5.7-2.3-3.2 0-5.6 1.1-7.2 3.4s-2.4 4.6-2.5 6.9v15.6h6v5.5h-17.1v-5.5h3.8V51.9c0-3.8-.7-6.4-2.1-7.9-1.4-1.5-3.3-2.3-5.6-2.3-3.2 0-5.5 1.1-7.2 3.3-1.6 2.2-2.4 4.5-2.5 6.9v15.8h6.9v5.5h-20.2v-5.5h6V42.4h-6.1v-5.6h13.4v6.4c1.2-2.1 2.7-3.8 4.7-5.2 2-1.3 4.4-2 7.3-2s5.3.7 7.5 2.1c2.2 1.4 3.7 3.5 4.5 6.4 1.1-2.5 2.7-4.5 4.9-6.1s4.8-2.4 7.9-2.4c3.5 0 6.5 1.1 8.9 3.3s3.7 5.6 3.7 10.2v18.2h6.1v5.5zm42.5 0h-13.2V66c-1.2 2.2-2.8 4.1-4.9 5.6-2.1 1.6-4.8 2.4-8.3 2.4-4.8 0-8.7-1.6-11.6-4.9-2.9-3.2-4.3-7.7-4.3-13.3 0-5 1.3-9.6 4-13.7 2.6-4.1 6.9-6.2 12.8-6.2s9.8 2.2 12.3 6.5V22.7h-8.6v-5.6h15.8v50.6h6v5.5zm-13.3-16.8V52c-.1-3-1.2-5.5-3.2-7.3s-4.4-2.8-7.2-2.8c-3.6 0-6.3 1.3-8.2 3.9-1.9 2.6-2.8 5.8-2.8 9.6 0 4.1 1 7.3 3 9.5s4.5 3.3 7.4 3.3c3.2 0 5.8-1.3 7.8-3.8 2.1-2.6 3.1-5.3 3.2-8zm61.5 16.8H269v-5.5h6V51.9c0-3.7-.7-6.3-2.2-7.9-1.4-1.6-3.4-2.3-5.7-2.3-3.1 0-5.6 1-7.4 3s-2.8 4.4-2.9 7v15.9h6v5.5h-19.3v-5.5h6V42.4h-6.2v-5.6h13.6V43c2.6-4.6 6.8-6.9 12.7-6.9 3.6 0 6.7 1.1 9.2 3.3s3.7 5.6 3.7 10.2v18.2h6v5.4h-.2z" style="fill: var(--text-primary);">path> g style="fill:blue;"> path d="M42 .2 13.4 92.3H1.7L30.2.2H42zM52.4.2v92.1H42V.2h10.4zm40.3 0L64.2 92.3H52.5L81 .2h11.7zM103.1.2v92.1H92.7V.2h10.4zM294 95h67v8.8h-67V95z">path> g> svg> 

The filters are applied in order. This is why the drop shadows are not the same color: the first drop shadow’s hue is altered by the hue-rotate() function but the second one is not.

Specifications

Browser compatibility

BCD tables only load in the browser

See also

  • CSS backdrop-filter property
  • CSS compositing and blending module, including the CSS background-blend-mode and mix-blend-mode properties.
  • The CSS mask property
  • SVG, including the SVG element and SVG filter attribute.
  • Applying SVG effects to HTML content

Found a content problem with this page?

This page was last modified on Jul 17, 2023 by MDN contributors.

Your blueprint for a better internet.

Источник

Читайте также:  Java script string to json
Оцените статью