How to display a binary search tree using CSS, HTML and a bit of Javascript?

后端 未结 2 951
轻奢々
轻奢々 2020-12-17 04:03

I want to \"paint\" the tree on screen using CSS and HTML and not represent it in any way or data structure ...

2条回答
  •  既然无缘
    2020-12-17 04:23

    A very simple way of creating a tree-like structure with HTML and CSS is nesting

    s
    Each div represents a node, and can have multiple nodes inside:

    //root
    //child 1
    //child 1.1
    //child 1.1.1
    //child 1.1.2
    //child 1.1.3
    //child 1.2
    //child 2

    Then you can add a margin-top to all divs, so that they appear under its parent div.

    A JSFiddle: http://jsfiddle.net/VxRmc/

    I've added percentage widths to each div. You can calculate widths if you know how many childs a node has. Or you can use fixed widths...

    Yeah, it's not a beautiful tree, but it can't be simpler.

提交回复
热议问题