css - 如何使 SVG 在 flexbox 内的 div 中调整大小?
问题描述
我的任务是根据 flexbox 的大小调整 SVG 的大小。
如果我删除<div>
that 的父级<svg>
,则 SVG 会正确缩放;但是,我不能这样做,因为需要有一个兄弟姐妹<svg>
我尝试了 flex-grow、flex-shrink、使用 height、max-height,但它们都不适合我,我很困惑。
澄清一下,底部#console
应该是固定高度(或不低于特定高度)。顶部#shape
应根据剩余高度调整大小。很多东西都是在 1000x500 的 viewbox 中绘制的,所以改变 viewbox 也不可行。
HTML(我在这里使用 Vue,但我认为这并不重要)
<template>
<div id="app">
<div id="main">
<div id="shape">
<svg viewBox="0 0 1000 500">
<polygon points="200,100 200,400 800,400 800,100" style="fill:lime" />
</svg>
<div style="position: absolute">I wanted to put something here to be the same size of this flexbox, so I need to wrap the SVG inside the div.</div>
</div>
<div id="console">
Some fixed height item
</div>
</div>
</div>
</template>
CSS
<style>
#main {
height: 95vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#shape {
}
#console {
height: 600px;
background-color: black;
color: white;
}
</style>
或在 Codepen 中查看:https ://codepen.io/kritsada_stw/pen/xxZowQX
解决方案
推荐阅读
- amazon-web-services - 如何防止某人在 Amazon SES 中使用我的域——他们使用不同的电子邮件地址从我的域发送电子邮件
- postgresql - 使用 psql 连接到具有自定义数据库集群位置的 postgres
- python-3.x - Pygame 与 PathLib?
- lda - 使用前向和后向方法进行线性判别分析
- angular - 如何使用 ngx-socket-io 发送凭据?
- typescript - Typescript - 如何查找具有属性的数组,然后在该数组中添加一个数组
- discord - 当一个或多个值相同时按两个属性对级别数据进行排序
- python - main.py 无法从模块中读取函数
- mongodb - 可以通过本地主机访问 Mongo 的 Pod,但不能访问服务名称
- azure - 是否可以监控 Azure 集成运行时?