Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style SVG circle with CSS

So I have my SVG-circle.

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">    <circle cx="168" cy="179" r="59" fill="white" /> </svg> 

I want it to be 120% when one hover the circle. I tried both with width, height and stroke. Haven't find any solution to make the circle bigger when hovering. Any suggestions?

circle:hover   {     stroke-width:10px;   }  circle:hover   {     height: 120%;     width: 120%;   } 
like image 500
Sebastian Avatar asked Jan 10 '13 10:01

Sebastian


People also ask

How do I style a SVG circle?

Code explanation:The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0,0) The r attribute defines the radius of the circle.

Can you use CSS to style SVG?

There are many Scalable Vector Graphics (SVG), but only certain attributes can be applied as CSS to SVG. Presentation attributes are used to style SVG elements and can be used as CSS properties. Some of these attributes are SVG-only while others are already shared in CSS, such as font-size or opacity .

How do you make a circle style in CSS?

To create a circle we can set the border-radius on the element. This will create curved corners on the element. If we set it to 50% it will create a circle. If you set a different width and height we will get an oval instead.

Which property would you use to change the color of an SVG using CSS?

The fill property is a presentation attribute used to set the color of a SVG shape.


2 Answers

As per the SVG 1.1 specification you can't style the r attribute of an SVG circle using CSS https://www.w3.org/TR/SVG/styling.html#SVGStylingProperties. But you can do:

<circle cx="168" cy="179" r="59"         fill="white" stroke="black"         onmouseover="evt.target.setAttribute('r', '72');"         onmouseout="evt.target.setAttribute('r', '59');"/> 

In SVG 2, which is partially supported by some modern browsers, you can style the r attribute of circles using CSS. https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes

like image 97
Peter Collingridge Avatar answered Sep 29 '22 10:09

Peter Collingridge


Want to only use CSS? Use line instead of circle.

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">     <style>     .circle {         stroke-width: 59;         stroke-linecap: round;     }     .circle:hover {         stroke-width: 71;     }     </style>     <line x1="168" y1="179" x2="168" y2="179" stroke="white" class="circle" /> </svg> 

http://jsfiddle.net/rLk7rd8b/

like image 21
interestinglythere Avatar answered Sep 29 '22 10:09

interestinglythere