How to apply a style to a single special HTML character across the page

16,971

Solution 1

I dont believe it can be done with CSS alone.

I would use jQuery to find and replace the &reg; content with <sup>&reg;</sup>

There is a similar question below with a correct answer on how to do this (saves me the trouble):

Altering registered symbols (R)

Solution 2

Unfortunately, I don't think you can just select certain characters with only CSS.

However...

  1. There is a CSS rule for superscript, and it is:

    vertical-align: super;
    
  2. This jQuery works:

    $(document).ready(function() {
       $('*').each(function() {
        var n = $(this).html().replace(
            new RegExp('®','g'),
            '<sup>®</sup>'
            ).replace(
            new RegExp('&reg;','g'),
            '<sup>&reg;</sup>'
            );
        $(this).html(n);
      });
    });​
    

I hope this helps!

Share:
16,971
BaronGrivet
Author by

BaronGrivet

Mountain bike obsessive, writer, coder, talker, social catalyst, enthusiastic arm waver, new father.

Updated on June 04, 2022

Comments

  • BaronGrivet
    BaronGrivet almost 2 years

    We've got a client who want's to superscript to "registered trademark" (®) character across their website.

    The website is CMS based and not only are they having trouble consistently superscripting characters but the superscript styling doesn't carry across to any CMS generated page titles etc.

    I'm wondering what are the possible/ best ways to achieve this:

    • Can CSS be used to apply a style to a specific special character?
    • Using jQuery to apply the style post page load.
    • Extending the template parsing engine (Silverstripe)

    Any ideas are appreciated.