V
V
Vladimir Novitsky2015-10-10 10:35:32
css
Vladimir Novitsky, 2015-10-10 10:35:32

How to style SVG with CSS?

Hello.
The question is the following. For example, there is a square in the form of SVG. It is white, located in a specific block:

<div>
   <div class="square"></div>
</div>
and loaded as a background via CSS:
.square {
    background:url('square.svg'); /* квадрат белого цвета */
    }

How to make it so that if the parent block has a certain class, then square.svg changes color:
<div class="black">
   <div class="square"></div>
</div>

.square {
    background:url('square.svg'); /* квадрат должен стать черного цвета */
    }

Type entry:
.black > .fil { /* .fil — это класс присвоенный в самом файле svg (<path class="fil" />) */
    fill:black;
    }
Does not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex K, 2015-10-10
@alexk111

To style an SVG with CSS, the SVG must be inserted as an HTML element in that document. In your case:

<div>
   <svg class="square black">
       ...
   </svg>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question