如何在README.md文件中创建键值对SVG图像(含示例样式)?
在README.md中创建键值对样式的SVG图像
直接嵌入SVG到README.md的方法
GitHub、GitLab等平台的README.md支持直接内嵌SVG代码,无需依赖外部图片链接,既避免了链接失效问题,也能让图像加载更稳定。你只需把SVG代码直接粘贴到README的合适位置即可。
复刻示例样式的SVG代码
针对你提供的示例样式,以下是可直接使用的SVG代码,包含键值对布局、分隔线和浅背景,匹配示例的视觉风格:
<svg width="420" height="180" viewBox="0 0 420 180" xmlns="http://www.w3.org/2000/svg"> <!-- 圆角背景 --> <rect width="100%" height="100%" fill="#f8f8f8" rx="6" ry="6"/> <!-- 顶部分隔线 --> <line x1="25" y1="40" x2="395" y2="40" stroke="#e0e0e0" stroke-width="1"/> <!-- 第一组键值对 --> <text x="25" y="65" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#666">Key</text> <text x="395" y="65" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#333" text-anchor="end">Value</text> <!-- 键值对分隔线 --> <line x1="25" y1="75" x2="395" y2="75" stroke="#f0f0f0" stroke-width="1"/> <!-- 第二组键值对 --> <text x="25" y="100" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#666">Another Key</text> <text x="395" y="100" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#333" text-anchor="end">Another Value</text> <!-- 键值对分隔线 --> <line x1="25" y1="110" x2="395" y2="110" stroke="#f0f0f0" stroke-width="1"/> <!-- 第三组键值对 --> <text x="25" y="135" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#666">Longer Key Name</text> <text x="395" y="135" font-family="system-ui, -apple-system, sans-serif" font-size="14" fill="#333" text-anchor="end">Longer Corresponding Value</text> </svg>
自定义调整说明
- 尺寸调整:修改
width和height属性,或通过viewBox适配不同显示需求 - 颜色修改:调整
fill(背景、文字颜色)和stroke(分隔线颜色)的属性值 - 字体适配:修改
font-family、font-size、font-weight属性匹配你的需求 - 增减键值对:复制
<text>和<line>元素组,调整y坐标控制垂直间距
内容的提问来源于stack exchange,提问作者Neomaster
相关产品推荐
相关产品推荐

