如何在GitHub README中实现github stats卡片横向并排对齐
失效原因说明
- Github README的渲染器会过滤所有自定义style属性,你写的flex布局样式会被直接移除,所以外层套flex容器的方案无法生效。
- 给img添加
align="center"只能让单张图片在当前行居中,不能实现多张图片横向并排的效果,所以该方案也不生效。
可行解决方案
方案1:使用HTML表格(兼容性最高,推荐)
Github完全支持原生HTML表格语法,用一行两列的表格承载两张卡片即可实现稳定的并排效果,不会出现错位问题,适配所有设备端。
代码示例:
<table> <tr> <td> <img src="https://github-readme-stats.vercel.app/api?username=user&show_icons=true&theme=radical" alt="User GitHub Stats" /> </td> <td> <img src="https://github-readme-stats.vercel.app/api/top-langs/?username=user&theme=radical&layout=compact" alt="Top Languages Card" /> </td> </tr> </table>
方案2:使用img的align属性
给第一张图片添加align="left"属性,两张图片的标签写在同一行不要换行,也可以实现并排效果。
代码示例:
<img align="left" src="https://github-readme-stats.vercel.app/api?username=user&show_icons=true&theme=radical" alt="User GitHub Stats" /><img src="https://github-readme-stats.vercel.app/api/top-langs/?username=user&theme=radical&layout=compact" alt="Top Languages Card" />
注意:该方案在小屏设备上可能会出现换行错位的情况,优先推荐表格方案。
内容的提问来源于stack exchange,提问作者user17458330
相关产品推荐
相关产品推荐

