Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Created July 11, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeMyUI/af8f630cbab40460c3ab4afb515c353e to your computer and use it in GitHub Desktop.
Save CodeMyUI/af8f630cbab40460c3ab4afb515c353e to your computer and use it in GitHub Desktop.
CSS Horizontal Family Tree
#wrapper
span.label Root
.branch.lv1
.entry
span.label Entry-1
.branch.lv2
.entry
span.label Entry-1-1
.branch.lv3
.entry.sole
span.label Entry-1-1-1
.entry
span.label Entry-1-2
.branch.lv3
.entry.sole
span.label Entry-1-2-1
.entry
span.label Entry-1-3
.branch.lv3
.entry.sole
span.label Entry-1-3-1
.entry
span.label Entry-2
.entry
span.label Entry-3
.branch.lv2
.entry
span.label Entry-3-1
.entry
span.label Entry-3-2
.entry
span.label Entry-3-3
.branch.lv3
.entry
span.label Entry-3-3-1
.entry
span.label Entry-3-3-2
.branch.lv4
.entry
span.label Entry-3-3-2-1
.entry
span.label Entry-3-3-2-2
.entry
span.label Entry-3-3-3
.entry
span.label Entry-3-4
.entry
span.label Entry-4
.entry
span.label Entry-5
// works with unlimited items
//------- {{ Variables }} -------//
$white: #eee9dc;
$bg: #2e6ba7;
$horizontal-gutter: 100px;
$border-radius: 10px;
$entry-min-height: 60px;
$label-width: 150px;
$label-height: 30px;
$label-border-radius: 5px;
//------- {{ Styles }} -------//
*, *: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: $white;
font: 16px Verdana, sans-serif;
background: $bg;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#wrapper {
position: relative;
}
.branch {
position: relative;
margin-left: $horizontal-gutter + $label-width;
&:before {
content: "";
width: $horizontal-gutter / 2;
border-top: 2px solid $white;
position: absolute;
left: -$horizontal-gutter;
top: 50%;
margin-top: 1px;
}
}
.entry {
position: relative;
min-height: $entry-min-height;
&:before {
content: "";
height: 100%;
border-left: 2px solid $white;
position: absolute;
left: -($horizontal-gutter / 2);
}
&:after {
content: "";
width: $horizontal-gutter / 2;
border-top: 2px solid $white;
position: absolute;
left: -($horizontal-gutter / 2);
top: 50%;
margin-top: 1px;
}
&:first-child {
&:before {
width: $border-radius;
height: 50%;
top: 50%;
margin-top: 2px;
border-radius: $border-radius 0 0 0;
}
&:after {
height: $border-radius;
border-radius: $border-radius 0 0 0;
}
}
&:last-child {
&:before {
width: $border-radius;
height: 50%;
border-radius: 0 0 0 $border-radius;
}
&:after {
height: $border-radius;
border-top: none;
border-bottom: 2px solid $white;
border-radius: 0 0 0 $border-radius;
margin-top: -$border-radius + 1px;
}
}
&.sole {
&:before {
display: none;
}
&:after {
width: $horizontal-gutter / 2;
height: 0;
margin-top: 1px;
border-radius: 0;
}
}
}
.label {
display: block;
min-width: $label-width;
padding: 5px 10px;
line-height: $label-height - 5px * 2;
text-align: center;
border: 2px solid $white;
border-radius: $label-border-radius;
position: absolute;
left: 0;
top: 50%;
margin-top: -($label-height / 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment