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.
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?
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.
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.
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.
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> .
I managed to achieve that with CSS...
div {
position: relative;
color: #0f0;
font-size: 28px;
}
div span {
height: 50%;
position: absolute;
color: #f00;
overflow: hidden;
}
<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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With