html - 如何使 <svg> 100% 宽度

标签 html svg

我正在尝试制作这个 <svg>元素拉伸(stretch)到屏幕宽度的 100%:

  <svg height="100" width="100">
   <path d="M0 0 L100 0 L50 100 Z" />
  </svg>

我需要做什么?

最佳答案

viewBox 定义了您可以看到的坐标。高度和宽度定义了 SVG 的大小。例如

html, body {
  width: 100%;
  height: 100%;
}
<svg height="100%" width="100%" viewBox="0 0 100 100"  preserveAspectRatio="none">
   <path d="M0 0 L100 0 L50 100 Z" />
</svg>

关于html - 如何使 <svg> 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32029094/

相关文章:

html - 将 tbody 设置为可滚动

javascript - 将条形图数据链接到 d3 工具提示

html - 使用 Svg 和 Transform 的小间隙(边距):Translate on some resolution

javascript - JQuery Div 成倍增加

javascript - 如何使用angularjs动态加载html表中的嵌套数组属性?

html - 为什么 css3 hover 效果在鼠标移动和点击时反转时会跳转?

javascript - 为什么文本没有像应有的那样更改为 'Testinghi'?

css - DIV 内的 SVG 显示不正确

javascript - 如何裁剪背景图片

javascript - 未捕获的类型错误 : Cannot read property 'getTotalLength' of null