Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display an alternate character with CSS?

I am using a web font that has several different, "M's" to choose from, in the glyphs panel. The default "M" that keeps being displayed in my website is hideous. I would like to use a better looking "M" from one of the font's alternate character choices.

In the glyphs panel (within Illustrator) the "M" character I want to use is: U+004d Alternates#2 (aalt2)

I have this currently in my CSS:

.script:before {
content: "\004D";
}

Unfortunately, this code does not pull the alternate "M" I want. It just pulls the default "M" that I'm trying to get rid of.

Is this even possible to call an alternate "M" from a font, and display it on a web page?

like image 788
Renee Avatar asked Mar 05 '15 20:03

Renee


People also ask

Can you use OTF in CSS?

Add a font-face section to your CSS code src: url('fonts/lovely_font. otf') format('opentype'); src: url('fonts/lovely_font. ttf') format('truetype'); As another optional efficiency measure, we can get the browser to check for a local copy of the font in case the user already has it.

How do you style each letter in CSS?

if not, you might want to wrap each letter within a span tag and assign it a CSS rule. #namer:first-letter { color:#09C; font-size:1.1em; font-weight:bold; } span { color:red; . . . } It looks a LOT cleaner if you dont use inline styling, you use n-th child css selector, and you create your own span and call it s.

How do I get alternate letters in font?

You can't access alternate glyphs in Microsoft Word, but you can access stylistic sets and contextual alternates in Word 2010 and higher. To do that, choose Format > Font and in the dialog box that opens, click Advanced and then click the Stylistic Sets menu. The switch for contextual alternates lies beneath that menu.


1 Answers

Ok the html code that corresponds to the font unicode character of 004D is "M" . Since you want to change all the occurences of the specifiv "M" to that particular character, just find the occurences of that character and add a span tag on the fly.

Here is an example where I have done the same thing with the character "e" but not "E". I changed "e" with "ȝ"

JSFIDDLE LINK here.

$(document).ready(function() {
  $.fn.texter = function() {
    var letters = $(this).html().split(""),
      text = "";

    for (var i in letters) {
      if (letters[i] == "e") {
        text += "<span class='" + letters[i] + "'>" + '&#541;' + "</span>";
      } else {
        text += letters[i];
      }
    }
    $(this).html(text);
  };

  $("body").texter();
});
.e {
  color: magenta;
  font-family: 'Arial';
  font-size: 18px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="text">Test Message is Entered Here EEE is not touched but eee is changed</div>

Another variation is to use the "unicode-range" attribute in @font-face to specify a new font and apply that new font to every occurence of the character. Refer MDN Documentation here.

The Fiddle for this can be found here ::: http://jsfiddle.net/dka30drt/7/

Code snippet here for the 2nd variation,

$(document).ready(function() {
  $.fn.texter = function() {
    var letters = $(this).html().split(""),
      text = "";

    for (var i in letters) {
      if (letters[i] == "e") {
        text += "<span class='" + letters[i] + "'>" + '&#541;' + "</span>";
        console.log(letters[i]);
      } else {
        text += letters[i];
        /*console.log(letters[i]);*/
      }
    }
    $(this).html(text);
  };

  $("body").texter();
});
@font-face {
  font-family: funkyfont;
  src: url(https://www.courts.mo.gov/civiceducation/html5bp/html5-boilerplate-4.3.0/css/webfontkit/alegreyasc-italic-webfont.eot?#iefix) format('embedded-opentype'), url(https://www.courts.mo.gov/civiceducation/html5bp/html5-boilerplate-4.3.0/css/webfontkit/alegreyasc-italic-webfont.woff) format('woff'), url(https://www.courts.mo.gov/civiceducation/html5bp/html5-boilerplate-4.3.0/css/webfontkit/alegreyasc-italic-webfont.ttf) format('truetype'), url(https://www.courts.mo.gov/civiceducation/html5bp/html5-boilerplate-4.3.0/css/webfontkit/alegreyasc-italic-webfont.svg#svgFontName) format('svg');
  unicode-range: U+004D;
}
.e {
  color: magenta;
  font-family: 'funkyfont';
  font-size: 18px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="text">Test Message is Entered Here EEE is not touched but eee is changed</div>

Hope this helps

like image 99
Sai Avatar answered Oct 23 '22 04:10

Sai