Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-tone font coloring in CSS?

Tags:

css

colors

fonts

I really like the look of two-tone buttons and fonts. I am thinking of when the top half of the font is one color and the bottom half is a variation on the same color. For an example see most of the buttons on an iPhone or the logo here http://ming.ly.

mingly

Is it possible to recreate this effect in CSS? Alternately is there a free tool I can use to generate fonts that look like this?

like image 635
Kevin Burke Avatar asked Jun 27 '11 05:06

Kevin Burke


People also ask

How do I put two colors in 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 I change the color of half text in CSS?

Half Style with CSS First, set the background property with the "linear-gradient" value to your prefered direction, and specify each color with 50% visibility. Then, set the background-clip property to "text" in order to make the background be painted within the foreground text.

How do you add mixed colors in CSS?

color-mix() Check the Browser compatibility table carefully before using this in production. The color-mix() functional notation takes two color values and returns the result of mixing them in a given colorspace by a given amount.

How do I make one word a different color in CSS?

To colored just one word you can use <span style="your style"> WORD</span> . This way you don't have to style the whole paragraph. Example: <p> The quick brown <span style="color: brown">fox</span> jumps over... </p> .


1 Answers

I managed to achieve that with CSS...

Example

Example

CSS

div {
    position: relative;  
    color: #0f0;
    font-size: 28px;
}

div span {
    height: 50%;
    position: absolute;
    color: #f00;
    overflow: hidden;  
}

HTML

<div>
    <span>Hello</span>
    Hello
</div>

jsFiddle.

Tested in Firefox 5.

Keep in mind that it is not very semantic to repeat the text to be displayed once.

Depending on the browsers you need to support, you could ditch that inner span for something like this in the CSS...

div:before {
    content: "Hello";
    height: 50%;
    position: absolute;
    color: #f00;
    overflow: hidden;   
}

jsFiddle.

As far as I know, there is no value for content which will automatically use that element's text node. You could put it on the title attribute and use attr(title) (or any other attribute).

You could also use JavaScript to do the repeating.

var textRepeat = document.createElement('span'),
    textRepeatTextNode = document.createTextNode(element.firstChild.data);

element.appendChild(textRepeat.appendChild(textRepeatNode));

If the first child was not necessarily a text node, you could use element.textContent || element.innerText.

like image 72
alex Avatar answered Oct 03 '22 02:10

alex