3

For a given text node on a page...

abcdefghijklmnop 

You can capitalize all letters with this:

selector { text-transform : uppercase; } /* Output: ABCDEFGHIJKLMNOP */ 

You can capitalize just the first letter with this:

selector { display : block; } selector:first-letter { text-transform: capitalize; } /* Output: Abcdefgijklmnop */ 

Is there any way to capitalize specific letters in the string besides the first letter? Example:

/* Pseudo code */ selector:nth-character(odd) { text-transform : uppercase; } /* Output: aBcDeFgHiJkLmNoP */ 
6
  • 1
    A simple google would answer this for you, and the answer is no. You need Javascript. Commented Aug 21, 2015 at 18:10
  • I think you need this: letteringjs.com Not possible with pure CSS. Commented Aug 21, 2015 at 18:10
  • Agree with the other comments, I'm afraid this is not possible with CSS alone as it cannot select text nodes. The only way this could be done with CSS is by changing the HTML and surrounding the letters in elements. Commented Aug 21, 2015 at 18:18
  • @Chrillewoodz Thank you for telling me that Google exists. Of course, when I Google this question in there, this very SO page the most relevant result I get. :) Commented Aug 21, 2015 at 18:23
  • Possible dup: stackoverflow.com/questions/15994270/… Commented Aug 21, 2015 at 18:25

1 Answer 1

3

It is not possible currently with pure CSS. But you can use the letteringjs.com plugin to implement it. You can read the Lettering.js Docs

$(document).ready(function() { $(".custom-caps").lettering(); });
.custom-caps > span:nth-child(even) { text-transform: uppercase; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://raw.githubusercontent.com/davatron5000/Lettering.js/master/jquery.lettering.js"></script> <div class="custom-caps">abcdefghijklmnop</div>

HTML:

<div class="custom-caps">abcdefghijklmnop</div> 

Rendered HTML:

<div class="custom-caps"> <span class="char1">a</span> <span class="char2">b</span> <span class="char3">c</span> <span class="char4">d</span> <span class="char5">e</span> <span class="char6">f</span> <span class="char7">g</span> <span class="char8">h</span> <span class="char9">i</span> <span class="char10">j</span> <span class="char11">k</span> <span class="char12">l</span> <span class="char13">m</span> <span class="char14">n</span> <span class="char15">o</span> <span class="char16">p</span> </div> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.