Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to enter ::before as a property of a tag? - Q&A

How to enter ::before as a property of a tag?

0 like 0 dislike

Need to do something like this:

Absolutely love the way the only thing that does not fit so it's through css or
Internet the leaf is already one and a half hours, yet found nothing I am sure this is already 100% ...
Thank you for any information.
asked by | 44 views

3 Answers

0 like 0 dislike
I'm sure this is already 100%

Mistaken =) it's not in principle.
The pseudo-element and pseudo it is because that it as it is, but it is not.

In General, enough to browse the Internet on this issue, and do as advised Ankhena — optional element.

I can recommend one trick, but its application is severely limited due to the use of properties for other purposes.


Another option is to use the classes, but again will only fit if you have a limited palette of colors.
answered by
0 like 0 dislike
answered by
0 like 0 dislike
If not using a separate css file with styles and not using a tag style, what about JavaScript? Running, for example, this trick:

<!doctype html>\r\r\r\r\r\rCONTENT DIVA\r\r\rvar UID = {\r_current: 0,\rgetNew: function(){\rthis._current++;\rreturn this._current;\r}\r};\r\rHTMLElement.prototype.pseudoStyle = function(element,prop,value){\rvar _this = this;\rvar _sheetId = "pseudoStyles";\rvar _head = document.head || document.getElementsByTagName('head')[0];\rvar _sheet = document.getElementById(_sheetId) || document.createElement('style');\ = _sheetId;\rvar className = "pseudoStyle" + UID.getNew();\r\r_this.className +=  " "+className;\r\r_sheet.innerHTML += "\."+className+":"+element+"{"+prop+":"+value+"}";\r_head.appendChild(_sheet);\rreturn this;\r};\r\rvar div = document.getElementById("testDiv");\rdiv.pseudoStyle("before","content","'перед'").pseudoStyle("before","color","green").pseudoStyle("before","background","black");\rdiv.pseudoStyle("after","content","'после'").pseudoStyle("after","color","red").pseudoStyle("after","background","yellow");\r\r
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


12.7k users

24,788 questions
46,220 answers
12,715 users