【问题标题】:svg wont scale to full height, parent flex, flex-direction: columnsvg 不会缩放到全高,父 flex,flex-direction:列
【发布时间】:2019-08-18 08:18:20
【问题描述】:

codepen 显示了我的设置。当 flex-direction 设置为 row 时,svg 应该与父级一起缩放。

希望你能帮到我

 flex-direction: column;

编辑:复制codepen代码

<div class="grandparent">
<div class="parent">
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" 
class="child" width="100%" height="100%">
  <line class="top" x1="0" y1="0" x2="300%" y2="0" />
  <line class="left" x1="0" y1="100%" x2="0" y2="-200%" />
  <line class="bottom" x1="100%" y1="100%" x2="-200%" y2="100%" />
  <line class="right" x1="100%" y1="0" x2="100%" y2="300%" />
</svg>
</div>
</div>


 .grandparent {
 height: 50vh;
 width: 50vh;

display: flex; 
flex-direction: column;
  }

 .parent {
  flex: auto;
 position: relative;
}

svg line {
   stroke-width: 3;
stroke: #000;
fill: none;
}

【问题讨论】:

  • 什么是flex:auto?我想你想要flex:1
  • 弹性:自动=弹性增长:1;弹性收缩:1;弹性基础:自动;

标签: css svg flexbox


【解决方案1】:

使用视图框而不是高度和宽度来缩放 svg。

示例:viewbox="0 0 100 100"。

https://css-tricks.com/scale-svg/

【讨论】:

  • 正方形只是一个例子,因为我必须设置 stroke-dasharray 相对于宽度和高度
猜你喜欢
  • 2019-11-18
  • 1970-01-01
  • 2019-02-25
  • 2020-06-26
  • 2015-12-05
  • 2017-08-03
  • 1970-01-01
  • 2013-12-06
  • 1970-01-01
相关资源
最近更新 更多