2017-04-13 44 views
0

我想创建某种形式的树形视图,尽管我不知道它是否是正确的单词。我画出它的照片让你明白我的意思。基本上它看起来像颠倒的花朵。 supposed tree-like view如何制作特定的“树视图”

这样做的最好方法是什么?对于每一个登录用户的用户,应该有一个新的分支,他的图片和名称以及分支机构的数量不受限制。 我想jQuery是这样,但我无法找到任何可以帮助我的东西。所以我会很高兴为jQuery插件或任何其他有用的提示的任何链接或提示。

+0

请阅读:[?我能在这里左右请问什么主题(http://stackoverflow.com/help/on-topic)。 _“问题**要求我们推荐或查找**书籍,工具,**软件库,教程或其他非现场资源,因为它们倾向于吸引自以为是的答案和垃圾邮件,所以不适合堆栈溢出。” _ –

+0

无代码无答案 – Gert

+1

您可以将其绘制为7列的列表,col1:用户1标签,col2:user1图像,col3:分支连接器,col4:水平线和col5:用于用户2等等。 – Anil

回答

2

我可能已经对这个答案有点过分了,但是测试一些东西很有趣,所以我提出了一个完整的解决方案。布局适应大多数元素的尺寸变化。我试图让CSS尽可能容易编辑。

您所需要做的就是根据需要多次复制level_2_entry_container。这可以通过几行代码轻松地在客户端或服务器端完成。内容结构在左侧和右侧都是相同的(方向和定位是通过CSS控制的)。

经过最新版Chrome和Firefox的测试。

body { 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-size: 12px; 
 
    color: #444; 
 
} 
 
.main_container { 
 
    min-width: 400px; 
 
    margin-top: 20px; 
 
    margin-bottom: 20px; 
 
} 
 
.solution_container { 
 
    position: relative; 
 
} 
 
.flex_container { 
 
    display: flex; 
 
    flex-direction: row; 
 
    flex-wrap: nowrap; 
 
    justify-content: center; 
 
    align-items: center; 
 
    position: relative; 
 
    z-index: 2; 
 
} 
 
.flex_item { 
 
    flex-grow: 1; 
 
    flex-shrink: 1; 
 
    flex-basis: 0; 
 
} 
 
.flex_item_static { 
 
    flex-grow: 0; 
 
    flex-shrink: 0; 
 
    flex-basis: auto; 
 
    position: relative; 
 
} 
 
.level_1_entry_image { 
 
    width: 160px; /* change according to preference */ 
 
    height: 160px; /* change according to preference */ 
 
    display: block; 
 
    border-radius: 50%; 
 
    box-sizing: border-box; 
 
    border: solid 4px #eee; 
 
    background-color: #eee; 
 
} 
 
.level_1_entry_content { 
 
    padding-left: 20px; /* change according to preference - controls text distance from level_1_image */ 
 
} 
 
.center_line { 
 
    position: absolute; 
 
    width: 4px; 
 
    height: 100%; 
 
    top: 0px; 
 
    left: 50%; 
 
    margin-left: -2px; 
 
    background-color: #eee; 
 
    z-index: 1; 
 
} 
 
.center_footer { 
 
    position: absolute; 
 
    width: 20px; 
 
    height: 4px; 
 
    bottom: 0px; 
 
    left: 50%; 
 
    margin-left: -10px; 
 
    background-color: #eee; 
 
    z-index: 1; 
 
} 
 
.level_2_entry_container { 
 
    width: 50%; 
 
    box-sizing: border-box; 
 
    margin-top: -50px; 
 
} 
 
.level_2_entry_container:first-child { 
 
    margin-top: 0px; 
 
} 
 
.level_2_entry_container:nth-child(odd) { 
 
    margin-right: auto; 
 
} 
 
.level_2_entry_container:nth-child(even) { 
 
    margin-left: auto; 
 
} 
 
.level_2_entry_image, 
 
.level_2_entry_content { 
 
    margin: 20px; /* change according to preference - controls level_2_image distance from central_line */ 
 
} 
 
.level_2_entry_image { 
 
    width: 100px; /* change according to preference */ 
 
    height: 100px; /* change according to preference */ 
 
    display: block; 
 
    border-radius: 50%; 
 
    box-sizing: border-box; 
 
    border: solid 4px #eee; 
 
    position: relative; 
 
    z-index: 2; 
 
    background-color: #eee; 
 
} 
 
.level_2_entry_container:nth-child(odd) .level_2_entry_image { 
 
    margin-left: 0px !important; 
 
    margin-bottom: 0px !important; 
 
} 
 
.level_2_entry_container:nth-child(even) .level_2_entry_image { 
 
    margin-right: 0px !important; 
 
    margin-bottom: 0px !important; 
 
} 
 
.level_2_entry_content { 
 
    margin-left: 0px !important; 
 
    margin-right: 0px !important; 
 
    margin-bottom: 0px !important; 
 
    padding: 20px; /* change according to preference - controls text distance from level_2_image */ 
 
    padding-top: 0px; 
 
    padding-bottom: 0px; 
 
} 
 
.level_2_entry_container:nth-child(odd) .level_2_entry_content { 
 
    padding-left: 0px !important; 
 
    text-align: right; 
 
} 
 
.level_2_entry_container:nth-child(even) .level_2_entry_content { 
 
    padding-right: 0px !important; 
 
    text-align: left; 
 
} 
 
.diagonal_line_1, 
 
.diagonal_line_2 { 
 
    position: absolute; 
 
    width: 75%; 
 
    height: 75%; 
 
    z-index: 1; 
 
    top: 0px; 
 
} 
 
.diagonal_line_1 { 
 
    right: 0px; 
 
} 
 
.diagonal_line_2 { 
 
    left: 0px; 
 
} 
 
.level_2_entry_container:nth-child(odd) .diagonal_line_2 { 
 
    display: none; 
 
} 
 
.level_2_entry_container:nth-child(even) .diagonal_line_1 { 
 
    display: none; 
 
} 
 
.level_2_entry_container:nth-child(odd) > .flex_container > .flex_item:nth-child(1) { 
 
    order: 1; 
 
} 
 
.level_2_entry_container:nth-child(odd) > .flex_container > .flex_item:nth-child(2) { 
 
    order: 2; 
 
} 
 
.level_2_entry_container:nth-child(even) > .flex_container > .flex_item:nth-child(1) { 
 
    order: 2; 
 
} 
 
.level_2_entry_container:nth-child(even) > .flex_container > .flex_item:nth-child(2) { 
 
    order: 1; 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta charset="UTF-8" /> 
 
     <meta http-equiv="content-type" content="text/html;charset=UTF-8"/> 
 
    </head> 
 
    <body> 
 
     <div class="main_container"> 
 
      <div class="solution_container"> 
 
       <div class="flex_container"> 
 
        <div class="flex_item"></div> 
 
        <div class="flex_item flex_item_static"> 
 
         <img class="level_1_entry_image" src="http://placehold.it/320x320"/> 
 
        </div> 
 
        <div class="flex_item"> 
 
         <div class="level_1_entry_content">Lorem ipsum dolor sit amet</div> 
 
        </div> 
 
       </div> 
 
       <div class="center_line"></div> 
 
       <div class="center_footer"></div> 
 
       <div class="level_2_container"> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
        <div class="level_2_entry_container"> 
 
         <div class="flex_container"> 
 
          <div class="flex_item"> 
 
           <div class="level_2_entry_content">Lorem ipsum dolor sit amet</div> 
 
          </div> 
 
          <div class="flex_item flex_item_static"> 
 
           <img class="level_2_entry_image" src="http://placehold.it/200x200"/> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_1"> 
 
            <line x1="10" y1="0" x2="0" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
           <svg viewbox="0 0 10 10" preserveAspectRatio="none" class="diagonal_line_2"> 
 
            <line x1="0" y1="0" x2="10" y2="10" stroke="#eee" stroke-width="0.4" /> 
 
           </svg> 
 
          </div> 
 
         </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    </body> 
 
</html>

+0

哇!非常好,非常感谢你!这正是我一直在寻找的。在此期间,我一直试图使用table和html5 canvas,因为我没有找到任何插件。但结果不是最好的:)这更好,谢谢!我感谢你的时间。 –

+0

现在我使用PHP进行动态化,编辑它一点,它的作用就像一个魅力。再次非常感谢:) –

+0

很高兴你发现它有用:) – Sebastian

相关问题