CSS和HTML的水平家谱

时间:2016-03-21 14:25:40

标签: javascript jquery html css css3

我在网上搜索过,发现后来在codepen中编辑了一个很好的家谱例子:http://codepen.io/anon/pen/bdLeNe。我的代码如下。

我正在努力解决2(css)问题:

  • 1:我需要调整树,以便在每个父链接的末尾(它与子级别相交)我可以画一个圆圈,但我唯一得到的就是在链接下面画圆圈。

这样的事情:

      ----- LN
      |
P --- O
      |
      ----- LN

其中P是Parent和LN叶节点。

  • 2:在原始示例中,叶节点没有内容(p,输入等)。如果他们在任何这些元素<span class="label">中都有它,它们会与它的兄弟重叠。我不知道如何使它们在相对定位时具有可变高度。我试过margin-top,但问题是链接不够高(节点断开连接)

我创建了一个要点:https://gist.github.com/leolanchas/9887b4e68db9f5894c9c

*, *:before, *:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  min-width: 1200px;
  margin: 0;
  padding: 50px;
  color: #eee9dc;
  font: 16px Verdana, sans-serif;
  background: #2e6ba7;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

#wrapper {
  position: relative;
}

.branch {
  position: relative;
  margin-left: 250px;
}
.branch:before {
  content: '';
  font-size: 40px;
  width: 50px;
  border-top: 2px solid #eee9dc;
  position: absolute;
  left: -100px;
  top: 50%;
  margin-top: 1px;
}

.branch:after {
  content: '\25CF';
  font-size: 40px;
  position: absolute;
  left: -100px;
  top: 50%;
}

.entry {
  position: relative;
  min-height: 60px;
}
.entry:before {
  content: "";
  height: 100%;
  border-left: 2px solid #eee9dc;
  position: absolute;
  left: -50px;
}
.entry:after {
  content: "";
  width: 50px;
  border-top: 2px solid #eee9dc;
  position: absolute;
  left: -50px;
  top: 50%;
  margin-top: 1px;
}
.entry:first-child:before {
  width: 10px;
  height: 50%;
  top: 50%;
  margin-top: 2px;
  border-radius: 10px 0 0 0;
}
.entry:first-child:after {
  height: 10px;
  border-radius: 10px 0 0 0;
}
.entry:last-child:before {
  width: 10px;
  height: 50%;
  border-radius: 0 0 0 10px;
}
.entry:last-child:after {
  height: 10px;
  border-top: none;
  border-bottom: 2px solid #eee9dc;
  border-radius: 0 0 0 10px;
  margin-top: -9px;
}
.entry.sole:before {
  display: none;
}
.entry.sole:after {
  width: 50px;
  height: 0;
  margin-top: 1px;
  border-radius: 0;
}

.label {
  display: block;
  min-width: 150px;
  padding: 5px 10px;
  line-height: 20px;
  text-align: center;
  border: 2px solid #eee9dc;
  border-radius: 5px;
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -15px;
}

.label input {
  display: block;
}
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<div id="wrapper">
  <span class="label">Root</span>
  <div class="branch lv1">
    <div class="entry"><span class="label">Entry-1</span>
      <div class="branch lv2">
        <div class="entry"><span class="label">Entry-1-1</span>
          <div class="branch lv3">
            <div class="entry sole"><span class="label">Entry-1-1-1</span></div>
          </div>
        </div>
        <div class="entry"><span class="label">Entry-1-2</span>
          <div class="branch lv3">
            <div class="entry sole"><span class="label">Entry-1-2-1</span></div>
          </div>
        </div>
        <div class="entry"><span class="label">Entry-1-3</span>
          <div class="branch lv3">
            <div class="entry sole"><span class="label">Entry-1-3-1</span></div>
          </div>
        </div>
      </div>
    </div>
    <div class="entry"><span class="label">Entry-2</span></div>
    <div class="entry"><span class="label">Entry-3</span>
      <div class="branch lv2">
        <div class="entry"><span class="label">Entry-3-1</span></div>
        <div class="entry"><span class="label">Entry-3-2</span></div>
        <div class="entry"><span class="label">Entry-3-3</span>
          <div class="branch lv3">
            <div class="entry"><span class="label">Entry-3-3-1</span>
              <div class="branch lv3">
                <div class="entry">
                  <span class="label">
                    <input type="text" disabled="" value="Entry-3-3-1-1">

                    <input type="text" disabled="" value="Entry-3-3-1-1">

                    <input type="number"></input>
                  </span>
              </div>
              <div class="entry"><span class="label">Entry-3-3-1-2</span></div>
              <div class="entry"><span class="label">Entry-3-3-1-3</span></div>
              <div class="entry"><span class="label">Entry-3-3-1-4</span></div>
              <div class="entry"><span class="label">Entry-3-3-1-5</span></div>
              <div class="entry"><span class="label">Entry-3-3-1-6</span></div>
            </div>
          </div>
          <div class="entry"><span class="label">Entry-3-3-2</span>
            <div class="branch lv4">
              <div class="entry"><span class="label">Entry-3-3-2-1</span></div>
              <div class="entry"><span class="label">Entry-3-3-2-2</span></div>
              <div class="entry"><span class="label">Entry-3-3-2-3</span></div>
              <div class="entry"><span class="label">Entry-3-3-2-4</span></div>
              <div class="entry"><span class="label">Entry-3-3-2-5</span></div>
              <div class="entry"><span class="label">Entry-3-3-2-6</span></div>
            </div>
          </div>
          <div class="entry"><span class="label">Entry-3-3-3</span></div>
        </div>
      </div>
      <div class="entry"><span class="label">Entry-3-4</span></div>
    </div>
  </div>
  <div class="entry"><span class="label">Entry-4</span></div>
  <div class="entry"><span class="label">Entry-5</span></div>
</div>

0 个答案:

没有答案