Code Snippet
Cufon 101
1. Include the JavaScript for Cufón and the Cufón font
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/TitilliumMaps.font.js"></script>2. HTML
Normal tags
<h1>Business Solutions</h1>
<h2>Business Insurance</h2>3. Tell Cufón to replace the fonts for the specified CSS selectors
<script type="text/javascript">
Cufon.replace('h1, h2', { fontFamily: 'TitilliumMaps26L', hover: true });
</script>4. Add JavaScript error handling in case there is an error loading
function handleError() { return true; }
window.onerror = handleError;5. CSS
The font color, size and hover color is controlled via the CSS classes associated with the HTML element.
h1 {
font-size: 50px;
color: red;
}
Hi, I’ve used Cufon on certain types, but one issue ive faced is that different fonts render in different sizes, that is say a 36px arial would be much larger than the 36px for my cufon-induced font, so if someone has javascript disabled, then the site looks messed up.
Any pointers on how to mitiage this? thanks.
Deane,
Check out the ‘Special Cases’ section under
http://wiki.github.com/sorccu/cufon/styling
When cufon replaces your elements, you can apply special CSS only after cufon has replaced text.
h1 {
font-size:2em;
}
The way this works, if Cufon fails to apply itself then your default css for the item h1 should get 2em size.
If Cufon succeeds, then you can make a rule like
.cufon-active h1 { /* for Cufon.replace(‘h1′) */
font-size: 3em;
}
so the cufon-rendered font is bigger.
yeah, don’t use that crap! Use web fonts instead, it’s just text.. jesus people go out of their way to screw up the internet! You can do worse than cufon though.. USE FLASH!
Don’t like
Is there any code or hack to skip the effect of preloading for cufon ?
Cufon don’t support Arabic..
sure we’ll find solution..:-)
any luck with arabic enabled solution??
@deane
I would load cufon normally and then have a normal stylesheet with text the size you want it. Then I would have javascript load in another stylesheet that overrides the first stylesheet and has the font sizes you need when using cufon. That way, if javascript is disabled, they don’t load cufon or the stylesheet associated with it. they just load the normal stylesheet. However, if javascript is enabled, it will load the styles that override the normal styles and allow for the correct cufon font styles.
Here’s an example:
<code&rt;
<script&rt;
var file = document.createElement(‘script’);
file.setAttribute(“type”,”text/css”);
file.setAttribute(“src”,theFile.ext)
</script&rt;
</code&rt;
Any way to get Cufin to load the replacement fonts without first flashing the un-replaced font in IE? I’m using Cufon, and it looks great in FireFox, but it’s unacceptable in IE because the page loads the “ugly” version first before Cufon kicks in with the pretty fonts. Does anyone know of a font replacement method that doesn’t do this? Thanks!
check out Cufon.now() in the documentation and #5 in the FAQ.
i usually set the element to display:none in the CSS, set text for element (usually via AJAX), cufon the element, and THEN .show() the element using jQuery.
i used it on a travel agency site’s home page to style dynamic text on a feature rotator and specials (http://shipsandtripstravel.com).
i also used it with multiple fonts on their testimonials page (http://shipsandtripstravel.com/about/testimonials.html)
Sorry, I meant Cufon not Cufin @~@
It’s not the best idea, but there are flash font replacements…
test
Hi,
cufon is not working for Arabic character.
could you please help me for this issue.
Thanks
In a wordpress template I have seen a HTML tag as . What does it mean?
@heena and @wdalhaj
I wrote a blog post about the The State of Arabic Webfonts it might prove helpful for what you are trying to accomplish. Cufon does not yet full support Arabic script.
works great with .html files but does anyone know how to place the script so it’s working with a .hta file?
it ain’t gonna work by simply renaming the file.
best regards
thomas
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.