css - 将线性渐变转换为 CSS 背景
问题描述
我有一个带有以下内容的 SVG:
<linearGradient id="path-2_2_" gradientUnits="userSpaceOnUse" x1="-275.652" y1="410.9046" x2="-275.0113" y2="412.0578" gradientTransform="matrix(46 0 0 -45.9998 12690 18947.9102)">
<stop offset="0" style="stop-color: rgb(248, 64, 24);"></stop>
<stop offset="0.6458" style="stop-color: rgb(248, 64, 24); stop-opacity: 0.6009;"></stop>
<stop offset="1" style="stop-color: rgb(248, 64, 24); stop-opacity: 0.2527;"></stop>
</linearGradient>
我正在尝试将其转换为 CSS 背景,但效果并不理想:
background: linear-gradient(
rgb(248, 64, 24) 0%
rgba(248, 64, 24 0.60) 65%,
rgba(248, 64, 24 0.25) 100%,
);
正在做某事,gradientTransform
但我不确定是什么,以及如何在我的 CSS 样式中复制它。
解决方案
要获得最终的渐变,您首先需要考虑x1/y1/x2/y2
定义方向(直到现在这很容易),然后您需要能够理解使用后对渐变所做的转换,gradientTransform
这不是微不足道的。因此,要么您是 SVG 和数学家大师,您可以进行计算以找到您需要在 CSS 中使用的值,或者您使用可以转换渐变的工具(如http://gradientfinder.com/)或者您查看在渐变处,您尝试对其进行近似。
我个人可以做近似:
.box {
background:
linear-gradient(30deg, rgb(248, 64, 24) 30%, rgba(248, 64, 24, 0.60) 42%, rgba(248, 64, 24, 0.25) 50%);
width: 400px;
height: 150px;
}
<svg height="150" width="400">
<defs>
<linearGradient id="path-2_2_" gradientUnits="userSpaceOnUse" x1="-275.652" y1="410.9046" x2="-275.0113" y2="412.0578" gradientTransform="matrix(46 0 0 -45.9998 12690 18947.9102)">
<stop offset="0" style="stop-color: rgb(248, 64, 24);"></stop>
<stop offset="0.6458" style="stop-color: rgb(248, 64, 24); stop-opacity: 0.6009;"></stop>
<stop offset="1" style="stop-color: rgb(248, 64, 24); stop-opacity: 0.2527;"></stop>
</linearGradient>
</defs>
<rect x="0" y="0" width="400" height="150" fill="url(#path-2_2_)" />
</svg>
<div class="box">
</div>
推荐阅读
- azure-devops - 使用 Linux Build 构建时,Azure Devops 无法在 nuget 包中找到文件
- javascript - 如何在 Typescript 中检测循环依赖
- java - .\gradlew build 显示“任务 ':applyBinaryPatches' 执行失败。> java/util/jar/Pack200”
- react-final-form - 另一个字段更改后字段更改时的反应最终表单句柄以及为什么formspy运行2次?
- docker - 如何使用 docker-java 的 detach 启动 docker 容器?
- cordova - Adobe 已停止 PhoneGap Build 并结束对 PhoneGap 和 Apache Cordova 的投资
- html - 如何在href标签中传递变量?
- reactjs - 测试套装因“SyntaxError: Unexpected token 'export”' react typescript using jest 失败
- node.js - Nodejs 和计算繁重的操作,通过工作线程最大限度地利用 cpu,同时仍然获得一些响应能力
- javascript - Jqplot - 单击一个点将其从数据库中删除