大写字符/单词的伪选择器?

发布于 2024-10-07 05:44:39 字数 133 浏览 0 评论 0原文

是否有用于大写字符/字母/单词的 CSS 伪选择器?我希望所有的大写字母都小一点,而所有其他字符的大小相同。大写不一定是句子(或单词)的第一个字符,反之亦然。

或者也许还有另一种方法可以在 CSS 中找到这些字符?有技巧吗?我喜欢把戏。

Is there a CSS pseudoselector for uppercase characters/letters/words? I want all my capitals to be a pt smaller and all the other characters 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮凉 2024-10-14 05:44:39

好吧,有一个支持不佳的 first-letter 选择器,但这不是你想要的。

当然,您也可以在 PHP 中预先解析 HTML,将所有大写字母包装在 标记中,但这是一种 hack。

当然,您总是可以拿出神奇的 jQuery 兔子并在文档加载时更改 DOM 以包含跨度。这也是一个黑客。你喜欢黑客吗?

让我们看看还有谁会表演魔术:-)

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 :-)

清旖 2024-10-14 05:44:39

我认为这是不可能的。

最好用一个类将大写字母包裹起来,并使用它来设置它们的样式。

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.

娇俏 2024-10-14 05:44:39

使用 CSS 是不可能做到这一点的。

您可以使用 Javascript 检查文本中的所有字符是否为大写(例如,使用 if (yourtext == yourtext.toUpperCase())),然后包装 在它们周围包含您的 CSS 来设置它们的样式。

或者围绕这些行的东西:

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');
    }
}

我没有尝试过(也许有人有时间用这个创建一个jsfiddle?),您可能需要使用 replaceNode 或类似的东西。 charCodeAt 方法仅查找大写字母,请注意,不会包含特殊希腊大写字母等 unicode 字符。
您现在只需要使用以下内容来设置跨度的样式:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文