所以我想放置在两列之间的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的最大高度。
谢谢您的帮助!
从height: 100%
元素删除svg
并添加align-self
财产拉伸,以便实现Flexbox本身会伸展出来在Flexbox的全高 - 见下面的演示和updated fiddle
:
html, body {
width: 100%;
height: 100%;
}
div.container {
margin: 40px auto;
width: 70%;
display: flex;
align-items: center;
}
.column {
display: inline-block;
width: 40%;
}
.column h3{
color: #1c3653;
font-size: 20px;
margin: 0px;
}
.column p {
color: #1c3653;
font-size: 15px;
}
svg {
display: block;
/*height: 100%;*/
width: 20%;
align-self: stretch; /* ADDED */
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<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>
您可以使用填充黑客:
你包在这种情况下,一个容器.svgDiv
您的SVG。该.svgDiv
有height:0
和padding-top:100%
使得它作为高度的容器。然后,你甘让你的SVG的宽度和容器的高度。
html, body {
width: 100%;
height: 100%;
}
div.container {
margin: 40px auto;
width: 70%;
display: flex;
align-items: center;
outline:1px solid;
}
.column {
display: inline-block;
width: 40%;
}
.column h3{
color: #1c3653;
font-size: 20px;
margin: 0px;
}
.column p {
color: #1c3653;
font-size: 15px;
}
svg {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.svgDiv{
width: 10%;
height:0;
padding-top:100%;
position: relative;
}
<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>
<div class="svgDiv">
<svg viewbox="0 0 100 100" preserveAspectRatio="none">
<line x1="50%" x2="50%" y1="0" y2="100%" style="stroke:rgb(0,0,0);stroke-width:1" />
</svg>
</div>
<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>
然而,这样做的另一种方法是
.svgDiv
在这种情况下,align-items: center;
to align-items: stretch;
的容器align-self:center;
的列。.svgDiv
(100%)的高度html, body {
width: 100%;
height: 100%;
}
div.container {
margin: 40px auto;
width: 70%;
display: flex;
align-items: stretch;
outline:1px solid;
}
.column {
display: inline-block;
width: 40%;
align-self:center;
}
.column h3{
color: #1c3653;
font-size: 20px;
margin: 0px;
}
.column p {
color: #1c3653;
font-size: 15px;
}
svg {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.svgDiv{
width: 10%;
position:relative;
}
<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>
<div class="svgDiv">
<svg viewbox="0 0 100 100" preserveAspectRatio="none">
<line x1="50%" x2="50%" y1="0" y2="100%" style="stroke:rgb(0,0,0);stroke-width:1" />
</svg>
</div>
<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>
<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>
我希望这有帮助。
你只需要添加一个高度.container
和.column
fiddle here
div.container {
margin: 40px auto;
width: 70%;
display: flex;
align-items: center;
height: 350px;
}
.column {
display: inline-block;
width: 40%;
height: 100%;
}