Style SVG circle with CSS

2020-02-08 08:01发布

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%;
  }

10条回答
Evening l夕情丶
2楼-- · 2020-02-08 08:43

You forgot the stroke color:

circle:hover {
    stroke:white;
    stroke-width:10px;
 }
查看更多
劳资没心,怎么记你
3楼-- · 2020-02-08 08:46

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/

查看更多
放我归山
4楼-- · 2020-02-08 08:46

Use this :

$(function () {
$('circle').hover(function () {
$(this).attr('r',100);
},function(){
$(this).attr('r',59);
});
});

Demo Here

查看更多
家丑人穷心不美
5楼-- · 2020-02-08 08:50

I am not sure, but you can not full custom a svg only with css. However, if you will do it won't be cross browser. In the past I used svg for creating a complex map and for me the solution was rapheljs.

EDIT:

Using @phonicx calculus for radius i modified the code, having something which is able to customize each circle ( in case if you have more ) :

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle data-precentage='100' cx="168" cy="179" r="59" fill="red" />
   <circle data-precentage='120' cx="74" cy="100" r="59" fill="black" /> 
</svg>
查看更多
登录 后发表回答