渐变与滤镜
SVG 里放文字用 text 元素,渐变用 defs 定义 linearGradient/radialGradient,图形引用渐变做填充。
文本
<text x="10" y="30" font-size="20" fill="#333">文字内容</text>。text-anchor 控制对齐(start/middle/end)。
线性渐变
defs 里定义 linearGradient(x1 y1 x2 y2 方向 + stop 色标),图形 fill="url(#渐变id)"。
代码示例
<svg width="400" height="150" xmlns="http://www.w3.org/2000/svg">
<!-- 定义渐变 -->
<defs>
<linearGradient id="greenGrad" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#7cb342" />
<stop offset="100%" stop-color="#33691e" />
</linearGradient>
<radialGradient id="radial" cx="50%" cy="50%" r="50%">
<stop offset="0%" stop-color="#fff9c4" />
<stop offset="100%" stop-color="#fbc02d" />
</radialGradient>
</defs>
<rect x="10" y="10" width="300" height="60"
rx="8" fill="url(#greenGrad)" />
<text x="160" y="50" text-anchor="middle"
font-size="22" fill="#fff">渐变标题文字</text>
<circle cx="360" cy="90" r="40" fill="url(#radial)" />
</svg>
📚 HTML 标签速查
常用条目速查,完整版见对应教程章节。可复制代码到在线运行中测试。
| 写法 / 语法 | 作用 |
|---|---|
<h1>-<h6> | 标题,h1 最高,每页只用一个 h1 |
<p> | 段落,自动加前后间距 |
<a href=""> | 链接,href 是目标地址 |
<img src="" alt=""> | 图片,src 地址,alt 替代文字 |
<ul> / <li> | 无序列表 |
<ol> / <li> | 有序列表,数字编号 |
<dl> / <dt> / <dd> | 自定义列表:术语 + 说明 |
<table> / <tr> / <td> / <th> | 表格:行 / 单元格 / 表头 |
<form action="" method=""> | 表单,action 提交地址,method 提交方式 |
<input type=""> | 输入控件,type 有 text/password/email/number 等 |
<textarea> | 多行文本输入 |
<select> / <option> | 下拉框及选项 |
<button type="submit"> | 按钮,submit 提交表单 |
<strong> / <em> | 加粗(重要)/ 斜体(强调) |
<div> / <span> | 区块容器 / 行内容器 |
<header> <nav> <main> | 语义化:页眉 / 导航 / 主体 |
<section> <article> <aside> | 语义化:分节 / 独立内容 / 侧栏 |
<footer> | 页脚:版权、备案 |
<video> / <audio> | HTML5 视频 / 音频,加 controls 显示控制条 |
<iframe src=""> | 嵌入其他网页 |
<!-- 注释 --> | HTML 注释,不显示在页面 |
<br> / <hr> | 换行 / 水平分割线 |
<pre> | 保留空格和换行,原样显示 |
<blockquote> / <q> | 块级引用 / 行内引用 |
<figure> / <figcaption> | 图文组合及说明 |