You are here: Blogsphere Authority
Keep up to date with your favourite Rails bloggers in context.
Automatic Fancy Ampersands with jQuery
Back in 2008, Dan Cederholm posted a great design tip on CSS-based fancy ampersands. The basics of this technique is that you surround every & in your headers with a <span class="ampersand"> tag. Then, in CSS, you define .ampersand as something like the following:
span.ampersand {
font-family: Baskerville, Palatino, "Book Antiqua", serif;
font-style: italic;
font-weight: normal;
}
…or, in Sass:
.ampersand
:font-family Baskerville, Palatino, "Book Antiqua", serif
:font-style italic
:font-weight normal
Fancy ampersands are one of those little details that adds a subtle aesthetic touch, and gives the page an extra notch of professionalism. Unfortunately, adding those spans by hand is both bothersome, and error-prone. It also becomes difficult to make use of this technique for existing or automatically generated content.
With a little addition to our application.js, we can have fancy ampersands inside all of our header tags (h1, h2, etc.):
$(document).ready(function(){
$(":header:contains('&')").each(function(){
$(this).html($(this).html().replace(/&/, "<span class='ampersand'>&</span>"))
});
});
You can see this in action on this site, where blog titles with an ampersand get all fancified.
2010 IT Tech Trends
Plagiarism today
coterie: A small group of p...
Resentment is like drinking...
“ Resentment is like drinking poison and waiting for the other person to die. ”
Carrie Fisher
1월 30일, TAEYO.NET 2010 신년 세미나
2010년 성공적인 IT 취업을 위한 조언 6선
WiFi만 잘 연결해도 밧데리가 충전이 된다.
Tell us what you think of the new BlogSphere feature. We are continually looking to improve and update the
functionality based on your feedback.

Find your next Ruby on Rails project or job.
Exclusive content,
regularly updated - onsite and tele-working positions listed.
Mohnish is a ruby expert, very friendly in nature. he helps other people a lot.
-
S.J, India