为什么此SVG图像的高度为150px

问题描述 投票:2回答:1

为什么此SVG图像在此500px容器内以150px高度显示?为什么这个具体价值?

我在js bin和Codepen中都发现了这种奇怪的行为,所以我认为它与我的代码有关,而不是与在线编辑器有关。

enter image description here

注意:700px div容器会产生相同的结果。所以父母的身高并不重要。

<div style="padding: 30px; background-color: yellow; height: 500px; width: 500px; ">
<svg>

  <pattern id="basicPattern" x="10" y="10" width="40" height="40" patternUnits="userSpaceOnUse" >
      <rect x= "0" y="0" width="4" height="4"
            stroke = "red"
            stroke-width = "1"
            fill = "black"/>
  </pattern>
  <!-- <rect x="0" y="0" width="300" height="151" // why this deletes the bottom line? -->
  <!-- <rect x="0" y="0" width="300" height="150" // why this deletes 1 px from the bottom line?  -->

  <!-- but this height="149" is the bottom limmit for this picture.. 
       what prevent's it bor beeing extended further -  we have unthil 500 px as you can see on the div.-->

  <rect x="0" y="0" width="300" height="149"
  stroke= "red" 
  stroke-width="2"
  fill="url(#basicPattern)" />
</svg>

This is Jsbinthis is CodePen.

svg jsbin codepen
1个回答
3
投票

您没有设置SVG widthheight,因此它的默认大小为300 px宽x 150 px高(对于某些用户代理)。

这是你的JSBin,SVG的宽度和高度都设置为500px。现在矩形可以超过150px的高度:https://jsbin.com/yafenemawe/1/edit?html,output

© www.soinside.com 2019 - 2024. All rights reserved.