1

i have a span like below :

<span  class="fa fa-fw fa-close">

and i want to have the fa-close in red color on hover, when I create the css class :

.fa-close:hover{color :red;}

it is applied to all spans with fa-close but i want it to be applied for just one span. How can i do it please?

1
  • Do you know the index of the span, and is it always the same? Can you use a more specific selector? Commented Jul 6, 2018 at 9:53

4 Answers 4

3

Add extra class to specific span where you want to apply red colour

For example

HTML

<span  class="fa fa-fw fa-close extra">

and CSS like

.fa-close.extra {color :red;}

So now, wherever you want to apply red colour you can add this class.

Hope this helps :)

Update as per PO requirement

If you want red colour only on hover then your code be like below

HTML

<span  class="fa fa-fw fa-close extra">

and CSS like

.fa-close.extra:hover {color :red;}
Sign up to request clarification or add additional context in comments.

4 Comments

in fact i want this red color to be applied on hover of fa-close any ideas please?
@gatkipper use css for hover instead of normal .fa-close.extra:hover {color :red;}
thank's for your reply , but the color is set red by default
remove .fa-close.extra {color :red;} and add .fa-close.extra:hover {color :red;}
0

Apply internal css to that span only:<span class="fa fa-fw fa-close" style=color:red>

Comments

0

If you want to apply css to only one element then you should use id instead of class.

#fa-close{color :red;}

Comments

-1

Add new class in span and then write css by using that class

HTML

<span  class="fa fa-fw fa-close apply_only_one">

CSS

.apply_only_one.fa-close{color :red;}

This is the best solution of your Problem.

2 Comments

why the copy of the same answer from another user?
not copy when i uploaded answer after writing ...then i saw that someone else also gave the same answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.