gpt4 book ai didi

html - 使用 :nth-child to style certain words

转载 作者:行者123 更新时间:2023-11-28 16:08:04 24 4
gpt4 key购买 nike

我可以使用 :nth-child 来选择(和设置样式)给定 HTML 元素中的特定单词吗?例如:

<h2 class="site-description">Four word long title</h2>

我想更改样式 -- 更改前两个单词的font-sizefont-style并使两个自动换行到另一行——无需更改 HTML,我无权访问它。

:nth-child 这可能吗?

如果这是完全错误的方法,那么还有其他选择吗?

最佳答案

不,它不适用于 :nth-child

因为 nth-child 只作用于子标签而不作用于字符串的字符

如果您不能更改 html,请尝试使用 jquery -或引用这个

Change color of selected text in a div using bootstrap & color picker

如果你可以编辑 html,你可以试试这个:

用 span 分隔字符并在该 span 上应用 css

希望有帮助

关于html - 使用 :nth-child to style certain words,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36080934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com