如何使css家族树造型“动态”

时间:2013-10-25 16:19:04

标签: html css

http://codepen.io/anon/pen/gubrp

在上面的链接中,可以注意到元素具有固定大小,当行变大时会发生以下情况

enter image description here

我想要的是css是动态的,就像它在下面的JSfiddle(盒子和线条)一样。我需要进行哪些修改才能使所有的盒子和线条变得动态而不是固定尺寸/固定位置?请注意,需要更改框和行。

http://jsfiddle.net/bZGFA/40/

以下是第一个示例中的css代码。

.root {
  position: relative;
}

.level {
  margin-left: 240px;
  position: relative;
}
.level:before {
  content: "";
  width: 50px;
  border-top: 2px solid #eee9dc;
  position: absolute;
  left: -98px; /*These fixed numbers are the problem but don't know how to solve it*/
  top: 50%;
  margin-top: 1px;
}

.item {
  min-height: 50px;
  position: relative;
}
.item:before {
  content: "";
  height: 100%;
  border-left: 2px solid #eee9dc;
  position: absolute;
  left: -48px; /*These fixed numbers are the problem but don't know how to solve it*/
}
.item:after {
  content: "";
  width: 46px;
  border-top: 2px solid #eee9dc;
  position: absolute;
  left: -46px; /*These fixed numbers are the problem but don't know how to solve it*/
  top: 50%;
  margin-top: 1px;
}

.item:first-child:before {
  width: 10px;
  height: 50%;
  top: 50%;
  margin-top: 2px;
  border-top-left-radius: 10px;
}
.item:first-child:after {
  height: 10px;
  border-top-left-radius: 10px;
}

.item:last-child:before {
  width: 10px;
  height: 50%;
  border-bottom-left-radius: 10px;
}
.item:last-child:after {
  height: 10px;
  border-top: none;
  border-bottom: 2px solid #eee9dc;
  border-bottom-left-radius: 10px;
  margin-top: -11px;
}

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

0 个答案:

没有答案