我的 h1 标签中有以下内容:(Hello World)",所以我将以下内容添加到我的 css 以更改此元素的第一个字符:
I have the following content in my h1 tag: "(Hello World)" so I add the following to my css to change the first character of this element:
h1:first-letter { font-size:63px; color:#510007; font-family:Helvetica; }
但是,正如我所注意到的,第一个字母仅用于字母,那么是否有任何解决方法可以将此样式应用于第一个字符?在这种情况下是(".
But, as I noticed, first-letter is only for letters, so is there any workarounds to apply this style to the first char? Which in this case is "(".
来自 规格:
标点符号(即 Unicode 中定义的字符 [UNICODE] 在open"(Ps)、close"(Pe)、initial"(Pi)、final"(Pf)和other"(Po)标点类)中,在第一个字母之前或之后应该是包括
Punctuation (i.e, characters defined in Unicode [UNICODE] in the "open" (Ps), "close" (Pe), "initial" (Pi). "final" (Pf) and "other" (Po) punctuation classes), that precedes or follows the first letter should be included
所以你的括号和字母H被:first-letter选中,因为(被认为是标点符号,而不是字母.
So your bracket and the letter H are selected by :first-letter, because ( is considered a punctuation symbol, not a letter.
有两种解决方法:
将左括号括在 span 标记中:
<!-- To style both (), wrap both in <span> tags -->
<h1><span>(</span>Hello World)</h1>
和目标h1 span:
h1 span {
font-size: 63px;
color: #510007;
font-family: Helvetica;
}
从文本中删除括号:
Drop the brackets from your text:
<h1>Hello World</h1>
并使用 :before 和/或 :after 代替(IE7 和更早版本不支持):
and use :before and/or :after instead (not supported in IE7 and older):
/* To style both (), use h1:before, h1:after */
h1:before {
font-size: 63px;
color: #510007;
font-family: Helvetica;
}
h1:before { content: '('; }
h1:after { content: ')'; }
这篇关于CSS 伪元素应用元素的第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
:target 为空时的 CSS 选择器CSS selector when :target empty(:target 为空时的 CSS 选择器)
CSS 直接后代 (>) 在选择性方面没有任何价值Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在选择性方面没有任何价值吗?)
使用 querySelectorAll().方法返回的结果是否有序?Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的结果是否有序?)
Safari 错误:当使用 JS 删除项目时,first-child 不更Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 错误:当使用 JS 删除项目时,first-child 不更新
nth-子 CSS 选择器nth-Child CSS selectors(nth-子 CSS 选择器)
对多个 HTML 标签使用相同的 ID?Using same ID for multiple HTML tags?(对多个 HTML 标签使用相同的 ID?)