/
<svg viewbox='0 0 80 80'>
<polygon id=button points='50,0 80,80 0,80'/>
<text x=40 y=50>HELLO</text>
</svg>
I have a polygon button with text on it and I want the polygon to get brighter when you hover over it. The problem is that when you hover over the text, the polygon goes back to dark.
I'd prefer to use mostly html/css but I'm fine with using javascript/jquery as long as I don't need another library.
I was hoping to do one of the following to solve it:
I thought this would be simple... I've run into some annoying limitations.
http://jsfiddle/J7psN/
<svg viewbox='0 0 80 80'>
<polygon id=button points='50,0 80,80 0,80'/>
<text x=40 y=50>HELLO</text>
</svg>
I have a polygon button with text on it and I want the polygon to get brighter when you hover over it. The problem is that when you hover over the text, the polygon goes back to dark.
I'd prefer to use mostly html/css but I'm fine with using javascript/jquery as long as I don't need another library.
I was hoping to do one of the following to solve it:
I thought this would be simple... I've run into some annoying limitations.
You can nest elements of an svg
using <g>
:
<svg viewbox='0 0 80 80'>
<g id=button>
<polygon points='50,0 80,80 0,80'/>
<text x=40 y=50>HELLO</text>
</g>
</svg>
and then apply css styling:
#button {
cursor: pointer;
fill: #900;
}
#button:hover {
cursor: pointer;
fill: #F00;
}
text {
font-size:7px;
fill: black;
}
See: http://jsfiddle/J7psN/1/
You can use:
$( "#button" ).hover(
function() {
$(this).css('fill' ,'#F00');
}, function() {
$(this).css('fill' ,'#900');
}
);
$('text').mouseover(function(e) {
$(this).prev().mouseover();
});
Updated Fiddle