简体   繁体   English

CSS中的伪元素

[英]Pseudo Elements in CSS

I'm currently working on a game's character database. 我目前正在研究游戏的角色数据库。 The character data and information about all the characters is written in JavaScript and the front end design is written in CSS. 字符数据和有关所有字符的信息均用JavaScript编写,而前端设计则用CSS编写。 Each character has certain attributes (attack, hp, recovery, etc.). 每个角色都有某些属性(攻击,生命值,恢复等)。 The one I'm focusing on is their Stars . 我关注的是他们的星星 Their stars refer to their rarity (1 star = extremely common; 6 stars = extremely rare). 他们的星标指的是他们的稀有性(1星=极为普通; 6星=极罕见)。 The game recently introduced a super evolution technique wherein a 6 star character can become a 6 star + (read as 6 star plus) character. 该游戏最近引入了一种超级进化技术,其中6星角色可以变成6星+(读作6星以上)角色。 This is where my problem is. 这是我的问题所在。 I know that the JavaScript will work just fine and I know that my problem is in the CSS. 我知道JavaScript可以正常工作,而且我的问题出在CSS中。 Please look at the code below. 请查看下面的代码。

This is the JavaScript for one of the Characters: 这是字符之一的JavaScript:

[ "Whitebeard: Four Emperors", "STR", [ "Striker", "Powerhouse" ], "6_plus", 65, 4, 5, 99, 5000000, 3148, 996, 142, 3806, 1558, 347, 1 ],

And the CSS to go with it: 与之配套的CSS:

.stars-6_plus:before { color: #00bfff; content: '\2605\2605\2605\2605\2605\2605\002B'; }

Ideally, I would change the JavaScript to say 6+ instead of 6_plus and the CSS the same way, but I can't figure out how to do it. 理想情况下,我将JavaScript改为6+,而不是6_plus和CSS,但是我不知道该怎么做。 I'm not sure if there even is a way to do it the way that I'm hoping for. 我不确定是否有一种方法可以按照我的期望进行。 I was told that maybe I could make a conditional so that it says 6+ when it reads 6_plus but I'm not sure if that's possible. 有人告诉我,也许我可以设置条件,以便在读取6_plus时显示6+,但我不确定是否可行。 I would really appreciate some help. 我真的很感谢您的帮助。

Thanks in advance. 提前致谢。

PS here's a link to the database if you'd like to check it out for yourself: PS如果您想亲自检查一下,这里是数据库的链接:

http://optc-db.github.io/characters/#/search/ http://optc-db.github.io/characters/#/search/

This should work for your class example. 这应该适用于您的课程示例。

*[class~="stars-6+"]:before{color:#00bfff; content:'\2605\2605\2605\2605\2605\2605\002B'; }

and the html 和HTML

<div class="stars-6+">
Hello
</div>

The javascript is straight forward and requires nothing special. javascript很简单,不需要任何特殊内容。

[ "Whitebeard: Four Emperors", "STR", [ "Striker", "Powerhouse" ], "6+", 65, 4, 5, 99, 5000000, 3148, 996, 142, 3806, 1558, 347, 1 ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM