::first-letter pseudo-element not working in firefox

荒凉一梦 提交于 2019-12-01 11:22:48

It seems to be due to the $ character not being interpreted as a letter character by Firefox, based on the discovery that replacing the $ with a letter character (A, B, C...) causes the demo to work:

<ul>
    <li><strong>David Wilcox</strong> <div>A$5,849,487<sup>84</sup></div></li>
    <li><strong>David Cowee</strong> <div>B$5,498,364<sup>01</sup></div></li>
    <li><strong>D.J. Johnson</strong> <div>C$5,098,276<sup>35</sup></div></li>
</ul>​

JS Fiddle demo.

Revisiting this question, though, it's worth noting that now you could use CSS generated-content to both supply, and style, a first-character, using ::before:

li div::before {
    content: '$';
    color: red;
}

With the HTML:

<ul>
    <li><strong>David Wilcox</strong> 
        <div>5,849,487<sup>84</sup>
        </div>
    </li>
    <!-- siblings removed for brevity -->
</ul>

JS Fiddle demo.

Everything works as it should do: ::first-letter selects the first letter, but "$" is not a letter but a special character.

Others already explained why it doesn't work, so, a small fix for you to consider: give your money div a class, eg

<li><strong>David Wilcox</strong> <div class="money">5,849,487<sup>84</sup></div></li>

take out the literal $, and put it in :before content, eg:

.money:before {
    content: '$';
    ...
}

Now you can style it however you like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!