【发布时间】:2020-10-23 20:46:19
【问题描述】:
我目前正在学习 css flexbox,我有一些关于在 flex box 中使用 svg 图像的问题。
如果是svg img is inside in the body of a html document,则svg 图像的宽度与正文的宽度相同。当我将display:flex 放入正文标记svg image in centered vertically and the size is reduced 时,它的行为与jpg image which would expand it whole height to match the body's height 不同.这是让我感到困惑的第一点。
第二点是当我输入the svg inside a div, the svg will disappear.。我读过stackoverflow post about this issue,它说这是因为 svg 没有设置内部宽度/高度。但是为什么在没有 div 的情况下 svg 图像没有消失呢?这是相同的图像,意味着内部宽度/高度也没有设置。 And If I put one more svg inside the div, the svg images magically appears with a tiny width and height.凹陷图像垂直而不是水平对齐。为什么在 div 中放入多个 svg 时它们会重新出现?
我很抱歉我的英语不好,因为英语不是我的母语。
【问题讨论】:
-
首先,尝试将宽度/高度属性添加到您的
标记中。您的问题与 SVG 无关。关于弹性。 flex 中的每个元素都表现为列或行。如果你想采用 100% 宽度添加
width: 100%或flex-basis: 100%。