css - Center SVG, preserveAspectRatio not working
问题描述
I want my SVG to be centered but it looks like this:
I'm trying to do preserveAspectRatio="xMidYMid meet"
to center it, but I'm obviously doing something wrong.
My tree and styling looks like this:
Can anyone see what I'm doing wrong?
解决方案
默认情况下,svg 是内联的,将这些行添加到 .triangle 类以使其居中:
display: block;
margin: 0 auto;
这将使其水平居中,如果您想要垂直,请按照以下步骤操作 ->
将这些行添加到 .triangle 类:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
将此行添加到您的 .icon_icon_3iAWn 类:
position: relative;
推荐阅读
- bash - 从 cron MacosX 运行时,Bash 丢失变量
- css - 我有这个 css 动画,当我在本地测试它时可以正常工作,但是当我将它启动到 github 页面时它不起作用
- amazon-web-services - 如何在 AWS 中将持久存储用于弹性搜索?
- rx-java - RxJava 延迟的懒惰
- android - 开启 VPN 时端口无法访问
- fastify - 如何将备份文件上传到 fasitfy 服务器?
- python - Python:使用 requests-html 进行网页抓取不起作用
- python - 如何创建具有相关表的对象
- python - json:期望值:第 1 行第 1 列(字符 0)
- android - Android 应用内更新 - 未立即检测到新版本