T
T
TtT RrR2022-04-02 20:32:45
css
TtT RrR, 2022-04-02 20:32:45

How to change the color of the link/text and svg at the same time when hovering over a link?

You need to change the color when hovering over the link.
The problem is that either the text is selected and the icon is not selected, or the text with the icon is selected when the cursor is on the icon. And you need both objects at the same time when hovering in the link zone.
Is it possible to do this for svg added via img tag? Or is it better to paste the svg file code?

<section>
        <ul>
            <li><a href="#">
                <img src="images/plane-solid.svg" alt="plane-solid.svg">
                    авиабилеты
                </a></li>
            <li><a href="#">
                <img src="images/plane-departure-solid.svg" alt="plane-departure-solid.svg">
                    чартеры
                </a></li>
            <li><a href="#">
                <img src="images/train-solid.svg" alt="train-solid">
                    ж/д билеты
                </a></li>
            <li><a href="#">
                <img src="images/hotel-solid.svg" alt="hotel-solid">
                    гостиницы
                </a></li>
            <li><a href="#">
                <img src="images/thumbs-up-solid.svg" alt="thumbs-up-solid">
                    туризм
                </a></li>
        </ul>
    </section>

*,::before,::after{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
ul{
    display: flex;
    list-style: none;
    justify-content: center;
    min-height: 40px;
    align-items: center;
}
a{
    display: flex;
    text-decoration: none;
    flex-direction: column;
    align-items: center;
    padding: 10px 15px;
    color: gray;
    text-align: center;
}
img{
    fill: gray;
    width: 50px;
    height: 50px;
    margin-bottom: 10px;
}
a:hover,img:hover{
    color: rgb(17, 97, 218);
    fill: rgb(17, 97, 218);
}

62488887c95ee691126284.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ankhena, 2022-04-02
@UNN4MED

These are not content images.
These are link decorations, they are made as backgrounds and/or pseudo-elements.
It is convenient to change the color using mask https://codepen.io/noahblon/post/coloring-svgs-in-...

Is it possible to do this for svg added via img tag?

You can use filters. The method is described in the article linked above. Little convenient.
Or is it better to paste the svg file code?

Better to remove images in css and use as mask.
Can be inlined in CSS using https://yoksel.github.io/url-encoder/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question