how to display span in column above a marked word without overlapping one another

Viewed 59

I'm trying to tag classes to a word in a description.

In case if there are multiple tags need to be assigned to a word then I need to display those classes on top of the word one above other in a stack.

but as in the below example, the classes are getting overlapped on previous one. i.e class2 is overlapping class1 making it not visible. similarly class4 hides class3

I tried with css properties like flex, flex-direction, position,flex-basis but whatever the value I gave the UI was still getting messed up. this below code is the neat UI I got as for now for debugging purpose.

<div dir="auto" style="line-height: 2.5;">
  <span data-start_offset="0" data-end="41" style="white-space: break-spaces;">Metaphysics continues asking "why" where </span>
  <span>
    <span style="position: relative;">
      <mark id="06aabd50-2b2a-4b45-bb5a-311630c7b2e8" data-start_offset="41" data-end="48" style="color: rgb(0, 0, 0); background: rgb(173, 164, 189); opacity: 1; position: relative; padding: 0px 4px; cursor: pointer;">science <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(173, 164, 189); opacity: 1; left: 0px; position: absolute; padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class1</span>
        <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(173, 164, 189); opacity: 1; left: 0px; position: absolute; padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class2</span>
      </mark>
    </span>
  </span>
  <span data-start_offset="48" data-end="194" style="white-space: break-spaces;"> of fundamental physics is based of fundamental physics is based of fundamental physics is based</span>
  <span>
    <span style="position: relative;">
      <mark id="977c207e-92ca-4176-af01-0b6b01afe578" data-start_offset="78" data-end="84" style="color: rgb(0, 0, 0); background: rgb(231, 131, 210); opacity: 1; position: relative; padding: 0px 4px; cursor: pointer;">theory <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(231, 131, 210); opacity: 1; left: 0px; position: absolute; padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class3</span>
        <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(231, 131, 210); opacity: 1; left: 0px; position: absolute; padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class4</span>
      </mark>
    </span>
  </span>
  <span data-start_offset="84" data-end="194" style="white-space: break-spaces;"> of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set.</span>
</div>

Expected output

the classes should be shown in a column one above the other on top of word. Then the line height should grow/adjust accordingly. can anyone help me

class1
class2
Tagged Word

1 Answers

compare your snippet if it does not will working fine then let me know into a comment below

mark{
  display:flex;
  flex-direction:column-reverse;
}
.child{
  display:inline-block;
  line-height: 1.7;
}

div .child:not(.last-child) {
  margin-bottom:10px;
}
/* make sure you add the last child to this class .last-child, because of we don't need to add extra margin to the last child element 
*/
<div dir="auto" style="line-height: 2.5;">
  <span data-start_offset="0" data-end="41" style="white-space: break-spaces;">Metaphysics continues asking "why" where </span>
  <span class="child">
    <span style="position: relative;">
      <mark id="06aabd50-2b2a-4b45-bb5a-311630c7b2e8" data-start_offset="41" data-end="48" style="color: rgb(0, 0, 0); background: rgb(173, 164, 189); opacity: 1; position: relative; padding: 0px 4px; cursor: pointer;">science <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(173, 164, 189); opacity: 1; left: 0px;  padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class1</span>
        <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(173, 164, 189); opacity: 1; left: 0px;  padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class2</span>
      </mark>
    </span>
  </span>
  <span data-start_offset="48" data-end="194" style="white-space: break-spaces;"> of fundamental physics is based of fundamental physics is based of fundamental physics is based</span>
  <span class="child last-child">
    <span style="position: relative;">
      <mark id="977c207e-92ca-4176-af01-0b6b01afe578" data-start_offset="78" data-end="84" style="color: rgb(0, 0, 0); background: rgb(231, 131, 210); opacity: 1; position: relative; padding: 0px 4px; cursor: pointer;">theory <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(231, 131, 210); opacity: 1; left: 0px;  padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class3</span>
        <span style="font-size: 0.7em; line-height: 1.5; background-color: rgb(231, 131, 210); opacity: 1; left: 0px;  padding: 0px 5px; font-style: italic; pointer-events: none; top: -11px; font-weight: bold; margin-left: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">class4</span>
      </mark>
    </span>
  </span>
  <span data-start_offset="84" data-end="194" style="white-space: break-spaces;"> of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set. of fundamental physics is based on some set.of fundamental physics is based on some set.</span>
</div>

Related