I have text between two floating elements, and the text is wrapping around the elements' shape outside. I want this text vertically centered on the page, but all vertical centering options I've tried cause the wrapping to break. This is how it looks right now:
I'm currently using padding-top: 40vh
to roughly center the text, but this breaks in a smaller viewport. I've tried doing padding-top: 50vh
and doing a transform translate(-50%)
but that doesn't work. I've also tried table, flex and grid layouts without success. Furthermore I tried absolute positioning of the text which, obviously, also breaks wrapping since the text gets removed from the flow. Setting the padding-top
dynamically with JavaScript is an option, but I would highly prefer a CSS solution.
Minimal example
html, body {
padding: 0;
margin: 0;
}
#container {
height: 100vh;
width: 100vw;
text-align: justify;
}
#left {
float: left;
width: 30vw;
height: 100vh;
background: red;
opacity: 0.1;
shape-outside: polygon(0 0, 30vw 0, 20vw 20vh, 20vw 80vh, 30vw 100vh, 0 100vh);
}
#right {
float: right;
width: 30vw;
height: 100vh;
background: green;
opacity: 0.1;
shape-outside: polygon(30vw 0, 0vw 0, 10vw 20vh, 10vw 80vh, 0vw 100vh, 30vw 100vh, 0 100vh);
}
#container p {
margin: 0;
}
<div id="container">
<div id="left"></div>
<div id="right"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce aliquam mattis sapien. Duis ut arcu sed nibh pretium ornare. Donec sed lacus viverra, pellentesque diam id, fringilla turpis. Donec egestas mauris libero, sit amet hendrerit nibh lobortis vel. Mauris sagittis elit libero, quis finibus arcu venenatis non. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
</div>