how can I make the first letter of each word capitalized when each word is capitalized?( :first-letter is not working )

huangapple go评论55阅读模式
英文:

how can I make the first letter of each word capitalized when each word is capitalized?( :first-letter is not working )

问题

我试图为一个具有属性 index=0 的元素分配样式。
选择器 :first-letter 不起作用。

如何使用属性选择器(在这种情况下 [index='0'] )来实现这个选择器?

我对第一个元素的期望输出是:
Text 0 Paragraph(红色文本)

英文:

I am trying to assign a style to an element where its attribute index=0
The selector :first-letter is not working.

How can do it the selector by attribute (in this case [index='0'] )?

My desired output for the first element is:
Text 0 Paragraph (red text)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

p[index=&#39;0&#39;]{
  color:red;
}

p[index=&#39;0&#39;]{
  text-transform: lowercase;
}

p[index=&#39;0&#39;]:first-letter {
  text-transform: uppercase;
}

<!-- language: lang-html -->

&lt;p index=&quot;0&quot;&gt;TEXT 0 PARAGRAPH&lt;/p&gt;
&lt;p index=&quot;1&quot;&gt;TEXT 1 PARAGRAPH&lt;/p&gt;
&lt;p index=&quot;2&quot;&gt;TEXT 2 PARAGRAPH&lt;/p&gt;
&lt;p index=&quot;3&quot;&gt;TEXT 3 PARAGRAPH&lt;/p&gt;

<!-- end snippet -->

答案1

得分: 1

:first-letter 只在第一个词上起作用。如果您的文本很短,您可以使用 :first-line。否则,您需要使用 JavaScript 来转换它。

p[index='0'] {
  color: red;
  text-transform: lowercase;
}

p[index='0']:first-line {
  text-transform: capitalize;
}
英文:

:first-letter only work on the first word. If your text is short you can use :first-line. Otherwise you need to use js to transform it

p[index=&#39;0&#39;]{
  color:red;
  text-transform: lowercase;
}

p[index=&#39;0&#39;]:first-line{
  text-transform: capitalize;
}

huangapple
  • 本文由 发表于 2023年6月15日 10:22:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定