SVG正在扩展到父级。

huangapple go评论52阅读模式
英文:

SVG is expanding past parent

问题

我一直在盯着这个问题,但无法弄清楚为什么这条线不考虑父元素的高度。我不能在事件容器上设置高度,我添加到示例中的其他高度只是为了取样。最终,我需要箭头线缩小/扩展到外部块的整体高度。
我在这里漏掉了什么?

英文:

I've been staring at this and can't figure out why the line isn't paying attention to the height of the parent elements. I can't set a height on the event-container, and the other heights I added to the demo are just for sampling. In the end, I need the arrow line to shrink down / expand up to the overall height of the outer block.
What am I missing here??

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.content {
  display: flex;
}

.container {
  display: inline-block;
  height: 100px;
}

.event-number {
  margin-right: 32px;
  margin-top: 8px;
  width: 28px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  height: 100%;
}

.event-circle {
  height: 28px;
  border-radius: 28px;
  background-color: #aac9ff;
}

p {
  margin: 0;
  padding-top: 4px;
}

.event-container {
  /*height: calc(100% - 36px);*/
}

.event-container .line {
  stroke: #aac9ff;
  stroke-width: 3px;
}

.event-container .box {
  overflow: visible;
}

.event-container .arrow {
  fill: #aac9ff;
}

<!-- language: lang-html -->

&lt;div class=&quot;content&quot;&gt;
  &lt;journey-counter class=&quot;hydrated&quot;&gt;
    &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;event-number&quot;&gt;
        &lt;div class=&quot;event-circle&quot;&gt;
          &lt;p&gt;1&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;event-container&quot;&gt;
          &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; xmlns=&quot;https://www.w3.org/2000/svg&quot;&gt;
            &lt;line class=&quot;line&quot; x1=&quot;50%&quot; y1=&quot;0&quot; x2=&quot;50%&quot; y2=&quot;100%&quot;&gt;&lt;/line&gt;
            &lt;svg class=&quot;box&quot; x=&quot;50%&quot; y=&quot;100%&quot;&gt;
              &lt;path class=&quot;arrow&quot; d=&quot;M-5 -10 l10 0 l-5 10 l -5 -10  Z&quot;&gt;&lt;/path&gt;
            &lt;/svg&gt;
          &lt;/svg&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/journey-counter&gt;
  &lt;div&gt;
    CONTENT
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

我最终通过使用纯CSS和flexbox来解决了这个问题。

https://jsfiddle.net/hornetnz/k27waym5/5/

.arrow-down {
  width: 0; 
  height: 0; 
  border-left: 5px solid transparent;
  border-right:5px solid transparent;
  border-top: 10px solid #aac9ff;
  margin-left: 10px;
}
英文:

I ended up solving this by using pure CSS & flexbox in place of SVGs.

https://jsfiddle.net/hornetnz/k27waym5/5/

.arrow-down {
  width: 0; 
  height: 0; 
  border-left: 5px solid transparent;
  border-right:5px solid transparent;
  border-top: 10px solid #aac9ff;
  margin-left: 10px;
}

huangapple
  • 本文由 发表于 2023年7月14日 03:29:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定