What I am looking for:
A way to style one HALF of a character. (In this case, half the letter being transparent)
What I have currently searched for and tried (With no luck):
- Methods for styling half of a character/letter
- Styling part of a character with CSS or JavaScript
- Apply CSS to 50% of a character
Below is an example of what I am trying to obtain.
Does a CSS or JavaScript solution exist for this, or am I going to have to resort to images? I would prefer not to go the image route as this text will end up being generated dynamically.
UPDATE:
Since many have asked why I would ever want to style half of a character, this is why. My city had recently spent $250,000 to define a new "brand" for itself. This logo is what they came up with. Many people have complained about the simplicity and lack of creativity and continue to do so. My goal was to come up with this website as a joke. Type in 'Halifax' and you will see what I mean.
Just for the record in history!
I've come up with a solution for my own work from 5-6 years ago, which is Gradext ( pure javascript and pure css, no dependency ) .
The technical explanation is you can create an element like this:
now if you want to make a gradient on text, you need to create some multiple layers, each individually specifically colored and the spectrum created will illustrate the gradient effect.
for example look at this is the word lorem inside of a
<span>
and will cause a horizontal gradient effect ( check the examples ):and you can continue doing this pattern for a long time and long paragraph as well.
But!
What if you want to create a vertical gradient effect on texts?
Then there's another solution which could be helpful. I will describe in details.
Assuming our first
<span>
again. but the content shouldn't be the letters individually; the content should be the whole text, and now we're going to copy the same <span>
again and again ( count of spans will define the quality of your gradient, more span, better result, but poor performance ). have a look at this:Again, But!
what if you want to make these gradient effects to move and create an animation out of it?
well, there's another solution for it too. You should definitely check
animation: true
or even.hoverable()
method which will lead to a gradient to starting based on cursor! ( sounds cool xD )this is simply how we're creating gradients ( linear or radial ) on texts. If you liked the idea or want to know more about it, you should check the links provided.
Maybe this is not the best option, maybe not the best performant way to do this, but it will open up some space to create exciting and delightful animations to inspire some other people for a better solution.
It will allow you to use gradient style on texts, which is supported by even IE8!
Here you can find a working live demo and the original repository is here on GitHub as well, open source and ready to get some updates ( :D )
This is my first time ( yeah, after 5 years, you've heard it right ) to mention this repository anywhere on the Internet, and I'm excited about that!
JSFiddle DEMO
We'll do it using just CSS pseudo selectors!
This technique will work with dynamically generated content and different font sizes and widths.
HTML:
CSS:
To wrap the dynamically generated string, you could use a function like this:
This can be achieved with just CSS
:before
selector andcontent property value
.>> See on jsFiddle
I've just finished developing the plugin and it is available for everyone to use! Hope you will enjoy it.
View Project on GitHub - View Project Website. (so you can see all the split styles)
Usage
First of all, make sure you have the
jQuery
library is included. The best way to get the latest jQuery version is to update your head tag with:After downloading the files, make sure you include them in your project:
Markup
All you have to do is to asign the class
splitchar
, followed by the desired style to the element wrapping your text. e.gAfter all this is done, just make sure you call the jQuery function in your document ready file like this:
Customizing
In order to make the text look exactly as you want it to, all you have to do is apply your design like this:
That's it! Now you have the
Splitchar
plugin all set. More info about it at http://razvanbalosin.com/Splitchar.js/.Here an ugly implementation in canvas. I tried this solution, but the results are worse than I expected, so here it is anyway.
You can use below code. Here in this example I have used
h1
tag and added an attributedata-title-text="Display Text"
which will appear with different color text onh1
tag text element, which gives effect halfcolored text as shown in below example