I’m trying to create a smooth transition when hovering over a selection. However, I added some text that has a stroke that is dashed. I am trying to include a smooth hover effect onto the text when a mouse hovers over it. For the life of me I cannot figure this out.
Please go to the CodePen for more examples
#box3 {
margin-top: 150px;
height: 300px;
width: 300px;
margin: auto;
background-color: #f2ece2;
border: 1px dashed black;
transition: background-color 0.3s, box-shadow 0.3s, border 0.3s, color 0.3s, transform 0.3s;
}
#box3:hover {
box-shadow: 5px 5px 0 black;
background-color: #ede2ce;
border: 1px solid black;
cursor: pointer;
}
#dashedText {
transition: stroke-dashoffset 0.3s ease;
}
#dashedText:hover {
color: black;
}
<div id='box3' class='btn-1'>
<h1>
<svg width="400" height="100">
<text id='dashedText' x="10" y="50" font-size="36" font-weight="bold" fill="none" stroke="black"
stroke-dasharray="4,2">
Hello There
</text>
</h1>
</div>
2
Answers
In SVG, the color property doesn’t directly control the color of the text. In your case, you are working with an SVG text element, and that’s why changing the color property did not have an effect. You need to use fill property to change the text color on hover.
I think you have missed to added javaScript code. Example that you have provided thare is used HTML, CSS for this box hover effect and Javascript for text hover effect may be you have not added javascript. Check below for working example.
Hi, I think you have missed to added javaScript code. Example that you have provided thare is used HTML, CSS for this box hover effect and Javascript for text hover effect may be you have not added javascript. Check below for working example.