html - 从包含图像的 svg 中删除多余的 "tail"

标签 html css svg

我有一个 png Logo ,我将其括在一个圆形 svg 中。 当使图像足够大时,我发现有很多多余的空白。

我是 svg 的新手,并尝试以我能找到的所有方式调整它的大小,但这最终会降低图像质量或大小。我尝试将 svg 放入 div 容器中并调整 div 大小,但没有成功。所附图片尺寸为 940 x 940 像素。

<div class="container" style="height:10%;width:100%; display:block;">
    <svg id="graph" class="text-center" width="100%" height="3500px" display="block">

        <defs>
            <pattern id="image" x="0%" y="0%" height="100%" width="100%"
                     viewBox="0 0 350 420">
                <a href="index.html">
                    <image x="0%" y="0%" width="512" height="512" xlink:href="img/CheesyTools2.png"></image>
                </a>
            </pattern>
        </defs>

        <circle id="sd" class="medium" cx="50%" cy="5%" r="5%" fill="url(#image)" stroke="black" stroke-width="0.5%" />
        <text text-anchor="middle" x="50%" y="11%" style="color:#274666; font-size:40px;">CheesyTools</text>
        <text text-anchor="middle" x="50%" y="12%" style="color:#274666; font-size:20px;">The world's leading website in being useless.</text>

    </svg>
</div>

显示 Logo 的图像:

enter image description here

我知道多余的空白来自 3500 像素的高度,但这是我可以使 Logo 尺寸适合网站的唯一方法。 我希望它具有相同的尺寸,但没有多余的高度。

真诚的,菜鸟。

最佳答案

我对您的 SVG 进行了相当多的更改。我使用的是 viewBox 属性,而不是 SVG 的宽度和高度。 SVG 并不像以前那么大,它只是图像和文本所需的大小。现在可以更轻松地使用 SVG 并将其放置在页面中您需要的任何位置。我希望它有帮助。

svg {
  border: 1px solid;
  width: 365px;
  height: 380px;
  margin: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
<svg id="graph" class="text-center" viewBox="245 45 365 380" display="block">

        <defs>
            <pattern id="image" x="0" y="0" height="100%" width="100%">
                <a href="index.html">
                    <image width="260" height="260" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/beagle400.jpg"></image>
                </a>
            </pattern>
        </defs>
 
        <circle id="sd" class="medium" cx="430.75" cy="175.075" r="127.5" fill="url(#image)" stroke="black" stroke-width="5" />
        <text text-anchor="middle" x="430.75" y="370" style="color:#274666; font-size:40px;">CheesyTools</text>
        <text text-anchor="middle" x="430.75" y="400" style="color:#274666; font-size:20px;">The world's leading website in being useless.</text>
  
    </svg>

关于html - 从包含图像的 svg 中删除多余的 "tail",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54343814/

相关文章:

javascript - 文本相对于 SVG 中的父 G 右对齐

javascript - 使用 d3.js 将鼠标 svg 转换为极坐标图坐标

javascript - 如何对齐一行中的图像

javascript - CSS Transition 在 jQuery .load 回调上失败

javascript - 导航栏不再滚动到页面上的部分?

javascript - ng-bind-html 添加了拥有的 css 类 'ng-binding',它破坏了所有嵌套的 css,如何摆脱它?

javascript - HTML - 根据标题展开/折叠? "document map"

javascript - SEO、PHP MasterPage 和渲染阻塞 Javascript/CSS

css - 在文本左侧显示图标

javascript - 向 SVG 圆添加线性渐变