Home > Web Front-end > CSS Tutorial > How Can I Fade Text into a Background Image Using CSS Gradients?

How Can I Fade Text into a Background Image Using CSS Gradients?

Linda Hamilton
Release: 2024-12-12 16:50:16
Original
272 people have browsed it

How Can I Fade Text into a Background Image Using CSS Gradients?

Applying Gradient Masks to Fade Text into Background

Web designers often encounter the challenge of creating text that visually blends with a fixed background image. One effective solution is to apply a gradient mask that fades the text toward the background at the top of the scrolling div.

To achieve this effect, Webkit browsers offer a straightforward CSS solution:

-webkit-mask-image: -webkit-gradient(linear, left 90%, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)))
Copy after login

This line of code fades out the bottom 10% of an element without relying on images. To ensure that content is only faded when there is more to scroll, consider adding padding-bottom: 50%.

In browsers that support CSS masks, such as Firefox and modern versions of Microsoft Edge, the following syntax is preferred:

mask-image: linear-gradient(180deg, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%);
Copy after login

This code creates a vertical gradient mask that fades out the bottom portion of the element, revealing the background image.

The above is the detailed content of How Can I Fade Text into a Background Image Using CSS Gradients?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template