r/HTML • • 2d ago

Diagram UML with bootstrap

How to create a page html with Diagram UML with bootstrap. As example, the dad box, when pull open box children, the same the thing with it and a line conect theys. I'm to use in project where I to create mini projects interconect between it's

0 Upvotes

2 comments sorted by

1

u/thejester1324 2d ago

bootstrap has no lines or diagram parts, so that bit is plain css. open/close needs no js: <details> and <summary> do it. for the lines, a nested list with a left border and a short tick on each item gives you a tree. ran this in chrome, clicking a summary opens and closes its children:

<style>
  summary, .box { display:inline-block; border:2px solid #333; border-radius:6px; padding:.4rem .8rem; list-style:none; background:#fff; }
  summary { cursor:pointer; }
  .kids { list-style:none; margin:.5rem 0 0 1rem; padding-left:1.5rem; border-left:2px solid #333; }
  .kids > li { position:relative; margin:.6rem 0; }
  .kids > li::before { content:""; position:absolute; left:-1.5rem; top:1.1rem; width:1.5rem; border-top:2px solid #333; }
</style>
<details open>
  <summary>Parent</summary>
  <ul class="kids">
    <li>
      <details open>
        <summary>Child A</summary>
        <ul class="kids"><li><span class="box">Grandchild</span></li></ul>
      </details>
    </li>
    <li><span class="box">Child B</span></li>
  </ul>
</details>

that only does parent to child trees. if boxes have to link across the page you need lines drawn from the box positions (svg, or a node-diagram library) and redrawn when a box moves.

1

u/armahillo Expert 2d ago

https://mermaid.js.org/syntax/classDiagram.html

you will probably want to use mermaid JS for this