开发者

pseudo selector for uppercase chars/words?

Is there a CSS pseudoselector for uppercase characters/letters/words? I want all my capitals to be a pt smaller and all the other charac开发者_开发知识库ters the same size. A capital is not neccesarily the first character of a sentence (or word) nor the other way around.

Or maybe there's another way to find these characters in CSS? With a trick? I like tricks.


Well, there's the poor-supported first-letter selector, but that's not what you want.

You could of course also pre-parse your HTML in PHP, wrapping all caps in <span class="capital"></span> tags, but that's a hack.

Then of course you could always pull out the magic jQuery rabbit and alter your DOM at document load to include the spans. That's also a hack. Do you like hacks?

Let's see who else turns up with a magic trick :-)


I do not think this is possible.

Better to just wrap the capital letters with a span with a class and use that to style them.


This is not possible using CSS.

You could use Javascript to check all characters in your text for uppercase (e.g. by using if (yourtext == yourtext.toUpperCase())) and then wrap a <span> around them containing your CSS to style these.

Or something around these lines:

function wrapCaps() {
    var text = document.getElementById("my_text").value;
    for(i=0; i < text.length; i++) {
        if(text[i].charCodeAt(text[i]) >= 65 && text[i].charCodeAt(text[i]) <= 90)
        wrapNode(text[i], 'span');
    }
}

I didn't try it out (maybe somebody has the time to create a jsfiddle with this?), you might need to use replaceNode or something like that. The charCodeAt method just looks for uppercase letters, please note that no unicode characters like special greek uppercase letters will be included.
You now only need to style your span with something like:

#my_text span {
    font-size: 10px;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜