CSS implements mask function
Previous words
CSS masks were added to the webkit engine by Apple in April 2008. Masking provides the ability to control the transparency of an element on a pixel level, similar to the effect of the alpha transparency channel in png24-bit or png32-bit. This article will introduce CSS mask mask in detail
Overview
The image is composed of three channels of rgb and the color defined on each pixel. But above them there is a fourth channel, the alpha channel, which defines the transparency on each pixel via brightness. White means opaque, black means transparent, and gray in between means translucent. Copyright belongs to the author.
The function of mask is to use a transparent picture or gradient to mask the background of the element. Therefore, the mask mask is very similar to the background, except that there is no color sub-attribute, and the remaining 6 sub-attributes of the background background, mask all have
. The mask mask is a composite attribute, including mask-image, mask- The eight attributes mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-size, and mask-composite
[Note] IE browser does not support it, and browsers with webkit kernel ( Including chrome, safari, IOS, android) you need to add the -webkit- prefix. It is important to note that the Firefox browser also supports the webkit-mask attribute
[mask-image]
The default value is none, the value is a transparent image, or a transparent gradient
[mask-repeat]
The default value is repeat, the optional value is the same as background-repeat, the details are here
[mask-position]
Default value is 0 0, the optional value is the same as background-position, the details are here
[mask-clip]
The default value is border-box, the optional value is the same as background-clip , the details are here
[mask-origin]
The default value is border-box, the optional value is the same as background-origin, the details are here
【mask-size】
The default value is auto, the optional value is the same as background-size, the details are here
【mask-mode】
The default value is match-source, the optional values are alpha, luminance, match-source, or their combination
[mask-composite]
The default value is add, the optional values are add, subtract, intersect, exclude
[Note] Only firefox supports mask-mode and mask-composite
Instance
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style>.wrap{position:absolute;width: 400px;border:1px solid black;}#mask{height: 300px;background:url() lightblue;-webkit-mask: url() no-repeat;animation: 2s maskPosition infinite alternate ;}#mask:hover{animation: none;}@keyframes maskPosition{0%{-webkit-mask-position:0 0;}100%{-webkit-mask-position:100% 100%;}}</style></head><body><p class="wrap"><p id="mask"></p> </p><script>var oBox = document.getElementById('mask'); oBox.onmousemove = function(e){ e = e || event; oBox.style.WebkitMaskPosition=(e.clientX-50)+"px "+ (e.clientY-50)+"px"; } </script></body></html>
The above is the detailed content of CSS implements mask function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
