英文:
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 -->
<div class="content">
<journey-counter class="hydrated">
<div class="container">
<div class="event-number">
<div class="event-circle">
<p>1</p>
</div>
<div class="event-container">
<svg width="100%" height="100%" xmlns="https://www.w3.org/2000/svg">
<line class="line" x1="50%" y1="0" x2="50%" y2="100%"></line>
<svg class="box" x="50%" y="100%">
<path class="arrow" d="M-5 -10 l10 0 l-5 10 l -5 -10 Z"></path>
</svg>
</svg>
</div>
</div>
</div>
</journey-counter>
<div>
CONTENT
</div>
</div>
<!-- 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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论