当前位置:网站首页>An article will take you to understand SVG gradient knowledge
An article will take you to understand SVG gradient knowledge
2020-11-06 20:42:00 【Python advanced】
Gradient is a smooth transition from one color to another . in addition , You can apply transitions of multiple colors to the same element .
SVG There are two main types of gradients :(Linear,Radial).
One 、SVG Linear gradient
<linearGradient> Element is used to define linear gradients .
<linearGradient> Tags must be nested in <defs> Internal .<defs> The label is definitions Abbreviation , You can define special elements such as gradients .
Linear gradients can be defined as horizontal , Vertical or angular gradients .
/*y1 and y2 equal , and x1 and x2 Different time , You can create horizontal gradients .
When x1 and x2 equal , and y1 and y2 Different time , You can create vertical gradients .
When x1 and x2 Different , And y1 and y2 Different time , You can create angular gradients .*/
example 1
Define the horizontal linear gradient from yellow to red ellipse .
SVG Code
<!DOCTYPE html>
<html>
<body style="background-color: aqua;">
<title> project </title>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
</body>
</html>
Running effect :
Code parsing :
-
<linearGradient> Labeled id Property defines a unique name for the gradient .
-
<linearGradient> Labeled X1,X2,Y1,Y2 Property defines where the gradient starts and ends .
-
The gradient's color range can be made up of two or more colors , Each color passes through a <stop> Label to specify .offset Property defines the start and end of the gradient .
-
Fill in the attribute to put ellipse Elements are linked to this gradient .
example 2
Define an ellipse with a vertical linear gradient from yellow to red .
SVG Code :
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
Running effect :
example 3
Define an ellipse , Horizontal linear gradient from yellow to red and adds an ellipse inner text .
SVG Code :
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" /> <text fill="#000" font-size="45" font-family="Verdana"
x="150" y="86"> SVG</text>
</svg>
Running effect :
Code parsing :
<text> Element is used to add a text .
Two 、SVG Radioactive gradients
<radialGradient> Element is used to define radioactive gradients .
<radialGradient> Tags must be nested in <defs> Internal .<defs> The label is definitions Abbreviation , It defines special elements such as gradients .
example 1
Define a radioactive gradient from white to blue ellipse .
SVG Code :
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(255,255,255);
stop-opacity:0" />
<stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
</radialGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
Running effect :
Code parsing :
-
<radialGradient> Labeled id Property defines a unique name for the gradient .
-
CX,CY and r The outermost circle and of the attribute definition Fx and Fy The innermost circle defined .
-
The gradient color range can be made up of two or more colors . Use one for each color <stop> Tag specified .offset Property is used to define the beginning and end of the gradient .
-
Fill in the attribute to put ellipse Elements are linked to this gradient .
example 2
Define another ellipse of radioactive gradients from white to blue .
SVG Code :
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <defs> <radialGradient id="grad1" cx="20%" cy="30%" r="30%"
fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:0" />
<stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
</radialGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
Running effect :
3、 ... and 、 summary
This article is based on HTML Basics , It introduces images SVG Gradient effects in elements , Through case analysis , What should be noticed in the actual project , Parse the code . The problems encountered in the development project , All of them provide some effective solutions .
Welcome to try , Sometimes it's easy to see someone else do it , But when it comes to doing it yourself , There will always be all kinds of problems , Don't hold your eyes high or your hands low , Do it frequently , Can understand more deeply .
The code is simple , Hope to help readers to learn better SVG.
Want to learn more Python Web crawler and data mining knowledge , Go to a professional website :http://pdcfighting.com/ Want to learn more Python Web crawler and data mining knowledge , Go to a professional website :http://pdcfighting.com/
版权声明
本文为[Python advanced]所创,转载请带上原文链接,感谢
边栏推荐
- 常用SQL语句总结
- Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
- Introduction to quantitative investment and Trading (Python introduction to financial analysis)
- 事务的本质和死锁的原理
- The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
- How does filecoin's economic model and future value support the price of fil currency breaking through thousands
- Cglib 如何实现多重代理?
- 一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
- 【转发】查看lua中userdata的方法
猜你喜欢
PHP application docking justswap special development kit【 JustSwap.PHP ]
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
C# 调用SendMessage刷新任务栏图标(强制结束时图标未消失)
面试官: ShardingSphere 学一下吧
To Lianyun analysis: why is IPFs / filecoin mining so difficult?
StickEngine-架构11-消息队列(MessageQueue)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
一部完整的游戏,需要制作哪些音乐?
【ElasticSearch搜索引擎】
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
随机推荐
image operating system windows cannot be used on this platform
Pollard's Rho algorithm
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
What course of artificial intelligence? Will it replace human work?
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
华为云微认证考试简介
MongoDB与SQL常用语法对应表
ado.net和asp.net的关系
How to understand Python iterators and generators?
【自学unity2d传奇游戏开发】如何让角色动起来
Flink的DataSource三部曲之一:直接API
What is alicloud's experience of sweeping goods for 100 yuan?
Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election
【ElasticSearch搜索引擎】
使用 Iceberg on Kubernetes 打造新一代雲原生資料湖
解决 WPF 绑定集合后数据变动界面却不更新的问题
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
Chainlink brings us election results into blockchain everipedia