backdrop-filter
Baseline
2024
Newly available
Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Thuộc tính backdrop-filter CSS cho phép bạn áp dụng các hiệu ứng đồ họa như làm mờ hoặc dịch chuyển màu sắc lên vùng phía sau một phần tử. Vì nó áp dụng cho mọi thứ phía sau phần tử, để thấy hiệu ứng, phần tử hoặc nền của nó cần phải trong suốt hoặc bán trong suốt.
Try it
backdrop-filter: blur(10px);
backdrop-filter: invert(80%);
backdrop-filter: sepia(90%);
<section class="default-example" id="default-example">
<div class="example-container">
<div id="example-element">Example</div>
</div>
</section>
.example-container {
background-image: url("/shared-assets/images/examples/balloon.jpg");
background-size: cover;
width: 200px;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
color: black;
}
#example-element {
font-weight: bold;
flex: 1;
text-align: center;
padding: 20px 10px;
background-color: rgb(255 255 255 / 0.2);
}
Cú pháp
css
/* Giá trị từ khóa */
backdrop-filter: none;
/* URL đến SVG filter */
backdrop-filter: url("common-filters.svg#filter");
/* Giá trị <filter-function> */
backdrop-filter: blur(2px);
backdrop-filter: brightness(60%);
backdrop-filter: contrast(40%);
backdrop-filter: drop-shadow(4px 4px 10px blue);
backdrop-filter: grayscale(30%);
backdrop-filter: hue-rotate(120deg);
backdrop-filter: invert(70%);
backdrop-filter: opacity(20%);
backdrop-filter: sepia(90%);
backdrop-filter: saturate(80%);
/* Nhiều filter */
backdrop-filter: url("filters.svg#filter") blur(4px) saturate(150%);
/* Giá trị toàn cục */
backdrop-filter: inherit;
backdrop-filter: initial;
backdrop-filter: revert;
backdrop-filter: revert-layer;
backdrop-filter: unset;
Giá trị
none-
Không có filter nào được áp dụng lên backdrop.
<filter-value-list>-
Danh sách phân tách bằng dấu cách các
<filter-function>hoặc SVG filter sẽ được áp dụng lên backdrop. Các<filter-function>CSS bao gồmblur(),brightness(),contrast(),drop-shadow(),grayscale(),hue-rotate(),invert(),opacity(),saturate()vàsepia().
Định nghĩa chính thức
| 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 |
Cú pháp chính thức
backdrop-filter =
none |
<filter-value-list>
<filter-value-list> =
[ <filter-function> | <url> ]+
<filter-function> =
<blur()> |
<brightness()> |
<contrast()> |
<drop-shadow()> |
<grayscale()> |
<hue-rotate()> |
<invert()> |
<opacity()> |
<sepia()> |
<saturate()>
<blur()> =
blur( <length>? )
<brightness()> =
brightness( [ <number> | <percentage> ]? )
<contrast()> =
contrast( [ <number> | <percentage> ]? )
<drop-shadow()> =
drop-shadow( [ <color>? && <length>{2,3} ] )
<grayscale()> =
grayscale( [ <number> | <percentage> ]? )
<hue-rotate()> =
hue-rotate( [ <angle> | <zero> ]? )
<invert()> =
invert( [ <number> | <percentage> ]? )
<opacity()> =
opacity( [ <number> | <percentage> ]? )
<sepia()> =
sepia( [ <number> | <percentage> ]? )
<saturate()> =
saturate( [ <number> | <percentage> ]? )
Ví dụ
>CSS
css
.box {
background-color: rgb(255 255 255 / 30%);
backdrop-filter: blur(10px);
}
body {
background-image: url("anemones.jpg");
}
HTML
html
<div class="container">
<div class="box">
<p>backdrop-filter: blur(10px)</p>
</div>
</div>
Kết quả
Đặc tả
| Specification |
|---|
| Filter Effects Module Level 2> # BackdropFilterProperty> |