I'm trying to insert a bunch of elements that are out of the flow but vertically aligned to inline elements.
Here is the result I want to achieve (yes it's ugly but it hopefully helps diagram the issue).
The HTML starts with a bunch of <span>bigger</span>
elements. To each <span>
some HTML template for a red arrow (⬅) is inserted. I want that red arrow to vertically align to the middle of the <span>
. The reason "bigger" has the 2 color background is to make it clear where the vertical middle is. The arrows need to vertically align with that middle.
Below is the code so far that doesn't work. To acheive my goal I can only change the CSS below the /* only change css below this line */
and the <template>
HTML. The point being I can not hard code heights for each situation. The solution must be fluid.
PS: I don't care about the "and"s. I only care the arrows point to the middle of their corresponding "bigger"
/* do not change any JavaScript */
const template = document.querySelector('#arrow');
document.querySelectorAll('span').forEach(elem => {
const child = template.content.cloneNode(true).children[0];
elem.appendChild(child);
});
.f1 { font-size: 10pt; }
.f2 { font-size: 15pt; }
.f3 { font-size: 25pt; }
.f4 { font-size: 30pt; }
.f5 { font-size: 35pt; }
.f6 { font-size: 40pt; }
.f7 { font-size: 45pt; }
.f8 { font-size: 50pt; }
.f9 { font-size: 55pt; }
.f10 { font-size: 60pt; }
.f11 { font-size: 65pt; }
.f12 { font-size: 70pt; }
/* only change css below this line */
.f {
background: linear-gradient(#e66465 50%, #9198e5 50%);
display: inline-block;
position: relative;
}
.arrow {
position: absolute;
right: 0;
top: 0;
display: inline-block;
}
.arrow>div:before {
content: 'f';
color: rgba(0,0,0,0);
}
.arrow>div {
position: absolute;
left: 0;
top: 0;
}
.arrow>div>div {
position: absolute;
bottom: 0;
color: rgba(255, 0, 0, 0.5);
font-size: 20pt;
}
<p>
Alice drank the potion and she got
<span class="f f1">bigger</span> and
<span class="f f2">bigger</span> and
<span class="f f3">bigger</span> and
<span class="f f4">bigger</span> and
<span class="f f5">bigger</span> and
<span class="f f6">bigger</span> and
<span class="f f7">bigger</span> and
<span class="f f8">bigger</span> and
<span class="f f9">bigger</span> and
<span class="f f10">bigger</span> and
<span class="f f11">bigger</span> and
<span class="f f12">bigger</span> and
</p>
<!-- only change html below this line -->
<template id="arrow">
<div class="arrow">
<div>
<div>⬅</div>
</div>
</div>
</template>