不按比例缩放SVG图像以适合剩余空间

如何解决不按比例缩放SVG图像以适合剩余空间

下方箭头由3个单个元素组成。中心部分应水平伸展,以便箭头可以填充其周围的容器。但是,正如您在呈现的代码中看到的那样,拉伸无法正常工作。如何进行拉伸并确保在接合处没有缝隙。可能由于antialiasing(这是强制性的),各部分之间应该有很小的重叠。

Arrow made of slices

编辑:使用@Turnip建议的return admin.database().ref('Support/issuesubtype/'+res).once('value') .then( snap => { 拉伸图像,但是会产生间隙并在某些宽度上跳跃。看这个截图:

enter image description here

根本无法解释这种奇怪的行为!

preserveAspectRatio="none"
.arrow {
  display: flex;
  max-width: 200px;
  padding-bottom: 2em;
}

.arrow svg {
  height: 25px;
  shape-rendering: auto;
}

#arrow-1 svg.stretched {}

#arrow-2 svg.stretched {
  width: 100%;
}

解决方法

我没有使用3个svg元素,而是仅使用了一个。我将“箭头”的开头和结尾放在<symbol>元素中,以便可以在需要的地方使用这些形状。请注意<symbol>元素具有紧密的视图框(viewBox紧紧包裹了形状,并且具有与形状的边界框相同的大小+线的1/2宽度的一些额外空间)。 / p>

现在,我可以根据需要和需要的地方多次使用这些符号。

为了连接2个use元素,我使用了一条线。请注意,该行(在第一组中)的x1属性是18,其中18 = 10(第一个使用元素的x属性)+ 8(第一个使用元素的width属性)。

该行的x2属性取决于您需要多长时间,并且具有与第二个use元素的属性x相同的值。

<svg viewBox="0 0 130 70">
  <symbol id="start" xmlns="http://www.w3.org/2000/svg" viewBox="5 0 8 22">
    <path fill="none" stroke="#000" stroke-miterlimit="10" stroke-width="3" d="M13 2.5h-1.31A5.21 5.21 0 006.5 7.69v14.62" />
  </symbol>

  <symbol id="end" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 25">
    <path fill="none" stroke="#000" stroke-miterlimit="10" stroke-width="3" d="M5.5 15.84V7.69A5.21 5.21 0 00.31 2.5H0" />
    <path d="M5.5 24.31l4.88-11.94-4.88 2.84-4.88-2.84L5.5 24.31z" />
  </symbol>

  <g id="g1">
    <use xlink:href="#start" x="10" width="8" height="22" />
    <use xlink:href="#end" x="100" width="11" height="25" />
    <line x1="18" y1="2.5" x2="100" y2="2.5" stroke="black" stroke-width="3" stroke-linecap="round" />
  </g>
  
  <g id="g2">
    <use xlink:href="#start" x="20" y="35" width="8" height="22" />
    <use xlink:href="#end" x="70" y="35" width="11" height="25" />
    <line x1="28" x2="70" y1="37.5" y2="37.5" stroke="black" stroke-width="3" stroke-linecap="round" />
  </g>
</svg>

,

您可以使用CSS发挥最大作用,并且更容易处理:

.box {
  width: 50%;
  margin: auto;
  height: 50px;
  border: 10px solid;
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  position: relative;
}

.box::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: -5px;
  width: 45px;
  height: 58px;
  transform: translate(50%,30%);
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 12 11 13"><path d="M5.5 24.31l4.88-11.94-4.88 2.84-4.88-2.84L5.5 24.31z"></path></svg>') bottom/contain no-repeat;
}
<div class="box"></div>

也如下:

.box {
  width: 50%;
  margin: auto;
  height: 50px;
  border: 10px solid;
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  position: relative;
}

.box svg {
  position: absolute;
  bottom: 0;
  right: -5px;
  width: 45px;
  transform: translate(50%,30%);
}
<div class="box">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 12 11 13"><path d="M5.5 24.31l4.88-11.94-4.88 2.84-4.88-2.84L5.5 24.31z"></path></svg>
</div>

,

在要拉伸的SVG上使用 const functions = require('firebase-functions'); const util = require('util'); exports.helloWorld = functions.https.onRequest((req,res) => { // For Firebase Hosting URIs,use req.headers['fastly-client-ip'] // For callable functions,use rawRequest // Some users have better success with req.headers['x-appengine-user-ip'] const ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress; const headers = JSON.stringify(req.headers,null,2); const message = util.format("<pre>Hello world!\n\nYour IP address: %s\n\nRequest headers: %s</pre>",ipAddress,headers); res.send(message); }); 。这将使内部preserveAspectRatio="none"与SVG元素一起伸展。

rect
.arrow {
  display: flex;
  max-width: 200px;
  padding-bottom: 2em;
}

.arrow svg {
  height: 25px;
  shape-rendering: auto;
}

#arrow-1 svg.stretched {}

#arrow-2 svg.stretched {
  width: 100%;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-