16

Is it possible in css make a single character in 2 colors?

I mean for example character "B" The first upper half in RED and the second half in BLUE

2
  • 1
    no, it is not possible, maybe you can try to superimpose two B letters and hide the top half for one, and the bottom half of the second one..
    – Mazeltov
    Commented Mar 5, 2014 at 10:55
  • 3
    take a look at stackoverflow.com/questions/6258690/…
    – keuleJ
    Commented Mar 5, 2014 at 11:09

2 Answers 2

3
h1 {
  font-size: 72px;
  background: -webkit-linear-gradient(red 49%, blue 50%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

Fill in your own vendor prefixes.

6
  • I don't mean the background! I mean the text color!
    – Apoleo
    Commented Mar 5, 2014 at 11:29
  • You didn't even try it did you?
    – slynagh
    Commented Mar 5, 2014 at 11:30
  • I did: jsfiddle.net/LZXTS/1
    – Apoleo
    Commented Mar 5, 2014 at 11:37
  • -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    – slynagh
    Commented Mar 5, 2014 at 11:42
  • yeah with chrome works! with firefox is not
    – Apoleo
    Commented Mar 5, 2014 at 11:46
2

One solution would be:

HTML:

<span class="half" title="B">B</span>

(see that you have to set an attribute value)

CSS:

  .half {
        font-size: 90px;
        font-weight: bold;
        position: relative;
        color: blue;
        line-height: 1em;
    }

    .half:before {
        position:absolute;
        content:''attr(title)'';
        color: red;
        height: .5em;
        overflow: hidden;
    }

The problem is that every browser calculates the .5em value differently

Not the answer you're looking for? Browse other questions tagged or ask your own question.