Please excuse my ignorance, SVG is very new to me. I'm trying to get a hover effect on a group of elements in my inline SVG. Each group of elements is a closely positioned set of circles. I can achieve this hover effect with css, but obviously this will only work when the mouse is positioned over a circle. What I want is the effect to work when the mouse is over the whole area that contains the circles, so spaces and circles combined.
<style>
svg {
height: 220px;
width: 400px;
background: grey;
}
.na circle,
.as circle {
fill: white;
}
.na:hover circle {
fill: blue;
}
</style>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<g class="na">
<circle cx="35%" cy="2.85%" r="2.8" />
<circle cx="36.75%" cy="2.85%" r="2.8" />
.
.
<circle cx="38.5%" cy="8.55%" r="2.8" />
<circle cx="40.25%" cy="8.55%" r="2.8" />
</g>
</svg>
http://jsfiddle.net/c3EaX/
See when moving the mouse over a group the hover flickers as you go between circle and space between them.
How would you go about getting the mouse over effect to appear to cover the whole area covered by the group? Is there an SVG element that can be used for this?
The simplest way to add a mouseover effect is to use the :hover pseudo-selector in CSS, as you would with an HTML element. CSS styles can be put in a separate document or inside a <style> tag inside the SVG itself.
To display div element using CSS on hover a tag: First, set the div element invisible i.e display:none;. By using the adjacent sibling selector and hover on a tag to display the div element.
The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.
The <g> SVG element is a container used to group other SVG elements. Transformations applied to the <g> element are performed on its child elements, and its attributes are inherited by its children. It can also group multiple elements to be referenced later with the <use> element.
The accepted answer didn't work for me. I found the following solution:
g {
pointer-events: bounding-box;
opacity: 0.4;
}
g:hover {
opacity: 1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With