css - 无法理解 viewbox 如何与 svg 一起工作而不提及视口(viewport),即高度和宽度

标签 css html svg viewport viewbox

viewbox 属性在没有视口(viewport)(即提到的高度和宽度)的情况下是如何工作的,在这种情况下,它占用了所有可用的宽度,但我不明白为什么?

<link rel="stylesheet" type="text/css" href="css.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">     </script>
</head>

<body>


<div>
<svg  viewBox="0 0 800 600" style="border:1px solid #000;">

<path d="M300,220 C300,220 520,220 540,220 C740,220 640,540 520,420 C440,340 300,200 300,200" id="top" stroke="red" stroke-width="3"fill="none"></path>

<path d="M300,320 L540,320" id="middle" stroke="red"></path>

<path d="M300,210 C300,210 520,210 540,210 C740,210 640,530 520,410 C440,330 300,190 300,190" id="bottom" transform="translate(0, 635) scale(1, -1) " stroke="red" stroke-width="3" fill="none"></path>

</svg>
</div>


<script src="js.js"></script>
</body>
</html>

最佳答案

如果有viewBox svg element's如果缺少宽度和高度属性(或样式),则使用 lacuna(默认)值。宽度和高度的空白值为 100%。

关于css - 无法理解 viewbox 如何与 svg 一起工作而不提及视口(viewport),即高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36002496/

相关文章:

css - 如何在 Material ui 中覆盖处于禁用状态的复选框颜色(框和字体)?

css - 对样式表所做的更改不可见

javascript - 非矩形、Canvas 或 SVG 形状内的背景动画?

css - 手机上的图标字体显示问题

html - 编写好的 "alt"内容?

javascript - 创建交互式 SVG HTML 表单的最佳方式

html - 当元素没有填满行时,不要在元素之间显示很大的差距

css - 覆盖 Flex 控件的标签级外部 CSS

html - 在新的 DIV HTML 标签中导入现有的 CSS 类

html - 变换 :translate not working in safari