I have a house icon and I want as soon as I hover over it the SVG changes to the text Home
Demo:
.fa-house:hover {
content: "Home";
}
<li routerLink="/home"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="house" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" color="#4d4d4e">
<path fill="currentColor"
d="M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z">
</path>
</svg>
</li>
CodePudding user response:
Make a parent
<div id="parent">
<svg className='your svg'/>
<div className='Home' />
</div>
when you will hover on parent, make svg display none, and div display flex. by default put on svg display flex, and on div with text a display none.
and don't forget about transition to make it beautifull.
If you don't understand the concept and need more explanation, I will give you full example based on your code, just ask. Have a perfect day!
CodePudding user response:
try below code, just change width and height of your svg and use below code,
#container{
display: grid;
grid-template-columns: 1fr;
grid-template-rows: repeat(3, 1fr);
}
#container img{
grid-column: 1;
grid-row: 1 / span 3;
width: 100%;
height: 100%;
overflow: hidden;
}
#container p{
visibility: hidden;
grid-column: 1;
grid-row: 2;
align-self: center;
justify-self: center;
z-index: 1;
}
#container:hover p{
visibility: visible;
}
#container:hover svg{
visibility: hidden;
}
<div id="container">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="house"
role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"
color="#4d4d4e">
<path fill="currentColor"
d="M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z">
</path>
</svg>
<p>SOME TEXT INSTEAD OF IMAGE</p>
</div>
comment if any query