Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Display One Character in 2 Colors [duplicate]

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

like image 639
Apoleo Avatar asked Mar 05 '14 10:03

Apoleo


2 Answers

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.

like image 189
slynagh Avatar answered Sep 22 '22 21:09

slynagh


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

like image 34
Iulian Anghel Avatar answered Sep 24 '22 21:09

Iulian Anghel