I am trying to create a unique angled text flow where the width of each line is a set value --w
. Below is the code I have so far:
* { margin: 0 }
html, body { display: grid }
body {
--w: min(35em, 65vw);
--f: 1/ 8;
background: linear-gradient(90deg, transparent var(--w), pink 0);
font: 1em ubuntu, sans-serif
}
.outer-wrapper {
width: min-content;
box-shadow: 0 0 0 2px red;
background: lemonchiffon
}
span::before, span::after {
--i: 0;
--j: calc(1 - var(--i));
--g:
linear-gradient(to right bottom,
hsla(50, 50%, 50%, var(--j)) 50%,
hsla(50, 50%, 50%, var(--i)) 0);
float: left;
height: 100%;
aspect-ratio: var(--f);
background: var(--g);
shape-outside: var(--g);
content: ''
}
span::after {
--i: 1;
float: right
}
.inner-wrapper {
width: var(--w);
box-shadow: inset 0 0 0 2px blue
}
<div class="outer-wrapper">
<span aria-hidden="true"></span>
<div class="inner-wrapper">
<p>Gingerbread macaroon cake topping wafer cake dessert. Lemon drops cheesecake lemon drops lollipop biscuit tart. Chupa chups bonbon dragée tart pie. Oat cake cupcake bear claw pie ice cream ice cream. Jelly beans ice cream icing halvah cotton candy. Tiramisu dragée macaroon chocolate bar chocolate cake. Sweet roll wafer candy gummies donut wafer liquorice sugar plum. Icing gummies chocolate cake gummies caramels sweet roll. Tootsie roll jelly beans jelly chocolate jelly beans pie. Halvah lollipop lemon drops shortbread bonbon. Jelly biscuit bear claw cotton candy cotton candy chocolate bar soufflé donut lollipop. Fruitcake lemon drops marshmallow sugar plum cheesecake gingerbread. Sugar plum chupa chups...
<p>Gingerbread macaroon cake topping wafer cake dessert. Lemon drops cheesecake lemon drops lollipop biscuit tart. Chupa chups bonbon dragée tart pie. Oat cake cupcake bear claw pie ice cream ice cream. Jelly beans ice cream icing halvah cotton candy. Tiramisu dragée macaroon chocolate bar chocolate cake. Sweet roll wafer candy gummies donut wafer liquorice sugar plum. Icing gummies chocolate cake gummies caramels sweet roll. Tootsie roll jelly beans jelly chocolate jelly beans pie. Halvah lollipop lemon drops shortbread bonbon. Jelly biscuit bear claw cotton candy cotton candy chocolate bar soufflé donut lollipop. Fruitcake lemon drops marshmallow sugar plum cheesecake gingerbread. Sugar plum chupa c...
<p>Gingerbread macaroon cake topping wafer cake dessert. Lemon drops cheesecake lemon drops lollipop biscuit tart. Chupa chups bonbon dragée tart pie. Oat cake cupcake bear claw pie ice cream ice cream. Jelly beans ice cream icing halvah cotton candy. Tiramisu dragée macaroon chocolate bar chocolate cake. Sweet roll wafer candy gummies donut wafer liquorice sugar plum. Icing gummies chocolate cake gummies caramels sweet roll. Tootsie roll jelly beans jelly chocolate jelly beans pie. Halvah lollipop lemon drops shortbread bonbon. Jelly biscuit bear claw cotton candy cotton candy chocolate bar soufflé donut lollipop. Fruitcake lemon drops marshmallow sugar plum cheesecak...
</div>
</div>
The issue I am facing is that I want the floated pseudo-elements on the sides to contribute to the --w
width and expand the .outer-wrapper
by one unit, as otherwise, the text overflows outside the red outlined box.
https://i.sstatic.net/anNXy.png
I am unsure how to achieve this using CSS alone. I know it can be done with JavaScript by detecting the pixel-valued height, storing it in a variable, updating it on resize, and recalculating from there. However, I would prefer a CSS-only solution.
Skewing the box is not a viable option in this scenario.