html - svg 宽度和高度内的图像无法按预期工作

标签 html css svg

我正在尝试使图像灰度在 IE 10 上工作,经过一些搜索使用 svg 可以将其存档,但现在我遇到了另一个问题,这是在 IE 10 上使图像灰度工作的代码

<svg xmlns="http://www.w3.org/2000/svg" id="svgroot" viewBox="0 0 400 377" width="400" height="377">
  <defs>
    <filter id="filtersPicture">
      <feComposite result="inputTo_38" in="SourceGraphic" in2="SourceGraphic" operator="arithmetic" k1="0" k2="1" k3="0" k4="0" />
      <feColorMatrix id="filter_38" type="saturate" values="0" data-filterid="38" />
    </filter>
  </defs>
  <image filter="url(&quot;#filtersPicture&quot;)" x="0" y="0" width="400" height="377" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://thecybershadow.net/misc/stackoverflow.png" />
</svg>

问题是图像没有按我给的尺寸缩放,例如,如果图像的尺寸是 200 X 1000,而我给的尺寸是 200 X 500,它会将图像缩放到大约 100 X 500

我试过 preserveAspectRatio http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute好像不行

所以我的问题是如何使图像调整到我给定的大小?

提前致谢

最佳答案

如果您希望图像拉伸(stretch)以完全填充您指定的宽度和高度(水平垂直),请使用preserveAspectRatio="none"

<image x="0" y="0" width="400" height="377" xlink:href="blah" preserveAspectRatio="none" />

关于html - svg 宽度和高度内的图像无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17540298/

相关文章:

html - 寻找更好的方法来设置可调整大小的背景 Css3/HTML/mootools

jquery - 字体大小等于当前容器的高度

javascript - 每次将元素添加到 SVG 时播放音频剪辑 - d3.js

javascript - 路径长度变化时保持 stroke-dasharray 一致

html - 将鼠标悬停在图像上时显示文本

html - PHP 文件因 Bootstrap 而部分失败

javascript - 无操作的 HTML 表单(+ CSP 规则无内联 javascript)

jquery - 如何实现漂移图像马赛克背景(下面给出的URL示例)

html - 带有圆边的 Jquery Mobile 表格

python - 使用 Python 将图像嵌入到 SVG 文件中,例如 Inkscape 扩展