Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display accents over words with different colors in HTML/CSS?

Tags:

html

css

colors

I have some text like this, displayed in HTML:

pīng​pāng​qiú​pāi

How can I change the text color, such that the text is blue while the accents above are red?

like image 708
Village Avatar asked May 08 '14 09:05

Village


People also ask

How do I make two words different colors in HTML?

Make separate elements Another way is creating a text with separate elements by using the HTML <span> tag, which is an empty container. This means that you create a multicolor text by putting each letter in a separate element to define a different color for each letter of your text.

How do you add multicolor text in CSS?

Steps to add multicolor into text: Add a simple text inside the <div> tag with the required selector. Apply the linear gradient property with any colors of your choice. Apply webkit properties that will fill the text with the gradient background and declare the color property with transparent background.

How do you put an accent on color?

Here is the key to doing it right: Use an accent color sparingly enough that it doesn't feel overpowering, use it in varying shades, don't just use it on the walls but add it in throughout your decor, and mix it in with two or three other colors to balance it out, so that the space doesn't start to feel like a ...

How do you put an accent over a letter in HTML?

In short, CTRL + ` is the escape sequence. Use CTRL + ' for an acute accent, CTRL + ^ for circumflex, CTRL + SHIFT + ~ for tilde, CTRL + SHIFT + : for umlaut, and CTRL + , for cedilla.


1 Answers

CSS treats the letter as a whole and therefore it can only be 1 colour.

Here is a hacky version:

This will only work if the content will stay the same.

span{
  font-size:48px;
  color:blue;
  position:relative;
}
span:after{
  content:'pīng​pāng​qiú​pāi';
  position:absolute;
  left:0;
  height:18px;
  overflow:hidden;
  z-index:9999;
  color:red;
  top:-5px;
}
<span>pīng​pāng​qiú​pāi</span>

Personally, I wouldn't use this. It's a horrible way of doing it.

like image 94
Albzi Avatar answered Nov 15 '22 08:11

Albzi