Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE11 browser shape overflows SVG element

I'm working on an SVG and trying to create half circle but the IE11 browser creates complete circle instead.

My code is like this:

<svg viewBox="0 0 80 40" class="gauge">
  <circle 
    cx="40"
    cy="40"
    r="37"
    fill="transparent"
    stroke="#d2d3d4"
    stroke-width="6"></circle>
</svg>

How can I render half circle in IE11? It is working fine on other browsers. Please find the below image for more reference.

On IE11 :

Image for IE11 browser

On Chrome :

Image for chrome

like image 664
Sanjay Raz Avatar asked Apr 11 '19 12:04

Sanjay Raz


1 Answers

A quick fix would be to add overflow:hidden; on the svg like so :

svg {
  overflow: hidden;
}
<svg viewBox="0 0 80 40" class="gauge">
  <circle 
    cx="40" 
    cy="40" 
    r="37" 
    fill="transparent" 
    stroke="#d2d3d4" 
    stroke-width="6"></circle>
</svg>

Depending on your use case, a "cleaner" solution would be to build your half circle with a path and the arc command :

<svg viewBox="0 0 80 40" class="gauge">
  <path d="M3 40 A37 37 0 0 1 77 40"
    fill="transparent" 
    stroke="#d2d3d4" 
    stroke-width="6" />
</svg>

This way you are sure nothing overflows the svg element.

like image 99
web-tiki Avatar answered Oct 17 '22 16:10

web-tiki