css - Change color of Font Awesome icons when they selected -


can change color of font awesome icon using ::selection pseudo-element?

i used that

.icon i::selection {   color: #fff; } 

or that:

.icon i:before::selection {   color: #fff; } 

and other variations. nothing worked.

font awesome icons added using :before/:after pseudo-elements.

.fa-stack-overflow:before {   content: "\f16c"; } 

since pseudo-elements don't exist in dom, it's not possible select them:

5.10 pseudo-elements , pseudo-classes

neither pseudo-elements nor pseudo-classes appear in document source or document tree.

to work around this, have avoid pseudo-elements , add icon html directly, isn't ideal. (example here)

therefore content: "\f16c" become &#xf16c;, have wrapped in .fa element correct font-family applied: <i class="fa">&#xf16c;</i>.

for example:

::selection {    color: #fff;  }
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">  selectable since it's added directly html: <i class="fa">&#xf16c;</i>

a more dynamic approach use javascript computed content value of pseudo-element , remove pseudo-element , replace unicode entity added directly html.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -