【发布时间】:2019-06-29 04:57:48
【问题描述】:
所以我试图在两列之间放置一条 SVG 线,但该线没有占用父容器的高度。父容器没有指定高度,因为我希望它自动缩放到最高列。
示例: https://jsfiddle.net/Lye0z5wx/4/
代码
html,
body {
width: 100%;
height: 100%;
}
div.container {
margin: 40px auto;
width: 70%;
display: flex;
align-items: center;
}
.column {
display: inline-block;
width: 40%;
}
svg {
display: block;
height: 100%;
width: 20%;
}
<body>
<div class="container">
<div class="column">
<h3>Content</h3>
<p>Easily change/switch/swap every placeholder inside every image on Sedna with the included Sketch files. You’ll have this template customised to suit your business in no time!</p>
<p>Nam vehicula malesuada lectus, interdum fringilla nibh. Duis aliquam vitae metus a pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum augue quis augue ornare, eget faucibus felis pharetra. Proin condimentum et leo
quis fringilla.</p>
</div>
<svg viewbox="0 0 100 100" preserveAspectRatio="none">
<line x1="50%" x2="50%" y1="0" y2="100%" style="stroke:rgb(235,235,235);stroke-width:1" />
Sorry, your browser does not support inline SVG.
</svg>
<div class="column">
<h3>Content</h3>
<p>Easily change/switch/swap every placeholder inside every image on Sedna with the included Sketch files. You’ll have this template customised to suit your business in no time!</p>
<p>Nam vehicula malesuada lectus, interdum fringilla nibh. Duis aliquam vitae metus a pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fermentum augue quis augue ornare, eget faucibus felis pharetra. Proin condimentum et leo
quis fringilla.</p>
</div>
</div>
</body>
我一直在尝试几种方法来完成这项工作,但 SVG 线在调整浏览器大小时会不断缩小。当我希望它包含父 div 的完整高度时。
感谢您的帮助!
【问题讨论】:
-
你可以在第一列设置一个border-right:1px solid stroke:rgb(235,235,235),所以你甚至不需要一个svg。
-
不确定我是否能以这种方式完美地居中,你会怎么做?
-
使用边框和填充的居中线:https://jsfiddle.net/y53d0wL6/
-
这确实简单多了!还有更好的浏览器兼容性,所以我会使用这个选项。