使用CSS设置句子的第一个单词的样式 [英] Style the first word of a sentence with CSS

查看:280
本文介绍了使用CSS设置句子的第一个单词的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用CSS为特定句子的第一个单词设置样式(即,我无法更改HTML).我觉得我已经接近答案了,但似乎无法正确回答.我正在使用的CSS选择器是:

I'm trying to style the first word of a specific sentence using only CSS (i.e. I can't change the HTML). I feel that I'm close to the answer but I can't seem to get it right. The CSS selector I'm using is:

main > h2:nth-child(2)+p {
  color: red;
}

我无法在此处发布HTML,因为它的格式不正确,但是可以在此JSFiddle上找到它: https://jsfiddle.net/gk0bwtvs/20/

I can't post the HTML here cause it's not getting formatted right, but it can be found on this JSFiddle: https://jsfiddle.net/gk0bwtvs/20/

谢谢

brld

再次:我无法更改HTMl,也无法添加任何形式的Javascript.

Again: I cannot change the HTMl, or add any sort of Javascript.

推荐答案

您将需要更改HTML,以将第一个单词放置在可以选择CSS的跨度中,或者需要使用JavaScript来检测第一个单词单词,然后使用JavaScript将该单词放在您可以使用CSS选择的跨度中.

You'll need to either change the HTML to place the first word in a span that you can select CSS, or you need to use JavaScript to detect the first word, then use JavaScript to place that word ina span that you can select with CSS.

只有一种方法可以完成此任务.创建您自己的浏览器应用程序,并添加对:first-word伪元素选择器的支持.

There is only one way to accomplish this. Create your own browser application, and add support for a :first-word pseudo-element selector.

这篇关于使用CSS设置句子的第一个单词的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆