大写字符/单词的伪选择器?
是否有用于大写字符/字母/单词的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,有一个支持不佳的 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 :-)
我认为这是不可能的。
最好用一个类将大写字母包裹起来,并使用它来设置它们的样式。
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.
使用 CSS 是不可能做到这一点的。
您可以使用 Javascript 检查文本中的所有字符是否为大写(例如,使用
if (yourtext == yourtext.toUpperCase())
),然后包装在它们周围包含您的 CSS 来设置它们的样式。
或者围绕这些行的东西:
我没有尝试过(也许有人有时间用这个创建一个jsfiddle?),您可能需要使用
replaceNode
或类似的东西。charCodeAt
方法仅查找大写字母,请注意,不会包含特殊希腊大写字母等 unicode 字符。您现在只需要使用以下内容来设置跨度的样式:
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:
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. ThecharCodeAt
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: