如何在css中增加svg图像的高度?

问题描述 投票:0回答:3

我正在研究svg图像(如带有四个三角形的箭头标记的屏幕截图所示)html代码如下所示,属于我想要增加它高度的网页。

enter image description here

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
   <style>.path-one,.path-two{fill-rule:evenodd;clip-rule:evenodd;fill:#00afc9}.path-two{opacity:.4;fill:#93c83d}</style>
   <path class="path-one" d="M30 30H0V0"></path>
   <path class="path-two" d="M0 30V0h30"></path>
</svg>

我尝试在svg标签中添加内联width="150px"height="150px",但它似乎不起作用。

问题陈述:

我想知道我应该在上面的代码中做出哪些更改,以便更改svg图像的高度

html css svg viewbox
3个回答
2
投票

您可以使用CSS实现相同的结果,并且更容易处理:

.box {
  display:inline-block;
  width:150px;
  height:150px;
  background:
    linear-gradient(to top left   ,transparent 49.3%,rgb(147, 200, 61,0.4) 50%),
    linear-gradient(to bottom left,transparent 49.3%,#00afc9 50%);
}
<div class="box">

</div>

您还可以将其整合为黑条的背景:

.box {
  height:60px;
  background:
    linear-gradient(to top left   ,transparent 49.3%,rgb(147, 200, 61,0.4) 50%),
    linear-gradient(to bottom left,transparent 49.3%,#00afc9 50%),
    #000;
  background-size:60px 100%;
  background-repeat:no-repeat;
}
<div class="box">

</div>

2
投票

将它应用于svg元素:

svg { width: 150px; height: 150px }

0
投票

请注意,svg图像实际上只使用高度和宽度属性来设置要设置的高度和宽度。然而问题在于你的道路。您可以为svg元素添加背景颜色,以验证它实际上是在更改高度和宽度。

<svg xmlns="http://www.w3.org/2000/svg" height="300" width="150" 
viewBox="0 0 30 
30" enable-background="new 0 0 311.7 311.5">
<path fill="red" class="path-one" d="M30 30H0V0"></path>
<path fill="blue" class="path-two" d="M0 30V0h30"></path>
</svg>

 <!-- CSS Code-->
<style>
svg {
  background-color: black;
}
</style>

一个可以快速播放SVG图像的网站是:https://www.rapidtables.com/web/tools/svg-viewer-editor.html

好好利用它。

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