Home >Web Front-end >CSS Tutorial >How to Create Dual-Color Text Without Duplicating Content?

How to Create Dual-Color Text Without Duplicating Content?

Barbara Streisand
Barbara StreisandOriginal
2024-11-12 15:54:02388browse

How to Create Dual-Color Text Without Duplicating Content?

Dual-Color Text Without Duplication

Duplicating content to achieve a dual-color text effect can be cumbersome. Here's a more elegant solution using purely HTML and CSS:

Using Background-Clip

Leveraging the background-clip: text property allows you to color the text with a gradient, providing immense flexibility in creating color combinations:

#main {
  background: linear-gradient(to right, red 50%, #fff 50%);
}

#main > p {
  background: linear-gradient(to left, blue 50%, #fff 50%);
  display: inline-block;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
<div>

This technique eliminates the need for duplicated content while enabling the creation of stunning and versatile dual-color text effects.

The above is the detailed content of How to Create Dual-Color Text Without Duplicating Content?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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