将 HTML5 SVG 与屏幕中心对齐

SVG 代表 Scalable Vector Graphics,它是一种用于在 XML 中描述 2D 图形和图形应用程序的语言,然后 XML 由 SVG 查看器呈现。

例子

让我们看一个 SVG 的例子 -

<!DOCTYPE html>
<html>
   <head>
      <style>
         #svgelem {
            position: relative;
            left: 50%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>SVG</title>
      <meta charset="utf-8" />
   </head>
   <body>
      <h2>HTML5 SVG Circle</h2>
      <svg id = "svgelem" height = "200" xmlns = "http://www.w3.org/2000/svg">
         <circle id = "redcircle" cx = "50" cy = "50" r = "50" fill = "red" />
      </svg>
   </body>
</html>

要使其居中,请添加如下 CSS -

 

#svgelem {
   margin-left:auto;
   margin-right:auto;
   display:block;
}

版权声明:本文为allway2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。