首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >居中OrgChart / FamilyTree的第一个和最后一个节点

居中OrgChart / FamilyTree的第一个和最后一个节点
EN

Stack Overflow用户
提问于 2019-03-05 03:18:00
回答 1查看 531关注 0票数 -1

我已经尝试了很多组织结构图,这个是独一无二的,因为它是为数不多的允许多个父级的。唯一的问题是第一个节点与应该在它下面的节点处于同一级别,并且最后一个节点不在父节点的下方居中。

请参见图像

这里的关键是让它自动调整。它是使用HTML-CSS制作的。不是我的。

代码语言:javascript
复制
<html>
<head >
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Test Family Tree</title>
<!-- I found and adapted this css code from: https://stackoverflow.com/questions/38192074/family-tree-css -->
<!-- There is also an example on codepen.io at: http://codepen.io/Pestov/pen/BLpgm -->
<!-- I am not sure who the original creator is -->
 
<style>
* {
margin: 0;
padding: 0;
font-family:sans-serif,Arial;
font-size:10pt;
}
.tree {
white-space: nowrap;
min-width: 800px;
min-height:500px;
}
.tree ul {
padding-top: 20px;
position: relative;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li {
float: left;
text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
/*We will use ::before and ::after to draw the connectors*/
.tree li::before, .tree li::after {
content: '';
position: absolute;
top: 0;
right: 50%;
border-top: 1px solid #ccc;
width: 50%;
height: 20px;
}
.tree li::after {
right: auto;
left: 50%;
border-left: 1px solid #ccc;
}
/*We need to remove left-right connectors from elements without any siblings*/
.tree li:only-child::after, .tree li:only-child::before {
display: none;
}
/*Remove space from the top of single children*/
.tree li:only-child {
content: '';
position: absolute;
top: 0;
right: 50%;
width: 50%;

}
/*Remove left connector from first child and right connector from last child*/
.tree li:first-child::before, .tree li:last-child::after {
border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.tree li:last-child::before {
border-right: 1px solid #ccc;
border-radius: 0 5px 0 0;
-webkit-border-radius: 0 5px 0 0;
-moz-border-radius: 0 5px 0 0;
}
.tree li:first-child::after {
border-radius: 5px 0 0 0;
-webkit-border-radius: 5px 0 0 0;
-moz-border-radius: 5px 0 0 0;
}
/*Time to add downward connectors from parents*/
.tree ul ul::before {
content: '';
position: absolute;
top: 0;
left: 50%;
border-left: 1px solid #ccc;
width: 0;
height: 20px;
}
.tree li div {
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: none;
color: #fff;
font-family: arial, verdana, tahoma;
font-size: 11px;
display: inline-block;
min-width: 80px;
min-height: 30px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
.tree li div .male {
background-color:#94A0B4;
display: inline-block;
width:fit-content;
padding:10px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
.tree li div .spacer {
background-color:lightblue;
display: inline-block;
width:10px;
}
/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li div:hover, .tree li div:hover + ul li div {
background: #c8e4f8;
color: #fff;
border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li div:hover + ul li::after,
.tree li div:hover + ul li::before,
.tree li div:hover + ul::before,
.tree li div:hover + ul ul::before {
border-color: #94a0b4;
}
</style>
 
<body>
 
<form id="form1">
 
<div class="tree" id="FamilyTreeDiv">
 
<ul>
 
<li>
<div><span class="male">Alpha
</span></div>
</li>
 
 
<li>
<div><span class="male">Beta
</span><span class="spacer"></span><span class="male">Beta-1
</span></div>
 
 
<ul>
 
<li>
 
<div><span class="male">Gamma
</span><span class="spacer"></span><span class="male">Gamma-1
</span></div>

<li>
<div><span class="male">Delta
</span></div>
</li>

<li>
 
<div><span class="male">Epsilon
</span><span class="spacer"></span><span class="male">Epsilon-1
</span></div>
 
 
<ul>
 
<li>
<div><span class="male">Theta
</span><span class="spacer"></span><span class="male">Theta
</span></div>
 
 
<ul>
 
<li>
<div><span class="male">Kappa
</span></div>
</li>
 
</ul>
</li>
 
 
<li>
<div><span class="male">Iota
</span></div>
</li>
 
</ul>
 
</li>
 
 
<li>
<div><span class="male">Eta
</span></div>
</li>
 
</ul>

非常感谢。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54990127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档