MENU

HTMLとCSSで作るシンプルでクールなカテゴリーツリー

シンプルでおしゃれなカテゴリーツリーを作りたい方へ。コピペですぐにできるので、よかったら使ってください。

カテゴリーツリー

デモ

シンプルだけど美しいカテゴリーツリーですね。

HTML


CSS


.category-tree > ul {
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.category-tree > ul ul {
  position: relative;
  margin: 0 0 0 1em;
  padding: 0;
  list-style-type: none;
}
.category-tree > ul ul:before {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 100%;
  content: '';
  border-left: 1px solid #fff;
}
.category-tree > ul ul li {
  position: relative;
  padding: 0 0 0 1.2em;
}
.category-tree > ul ul li:after {
  position: absolute;
  top: 1em;
  left: 0;
  bottom: 0;
  width: .7em;
  height: 0;
  content: '';
  border-top: 1px solid #fff;
}
.category-tree > ul ul li:last-child:after {
  height: auto;
  background-color: #34495e;
}
.category-tree > ul li {
  line-height: 2;
}
.category-tree > ul li a {
  color: #ddd;
  text-decoration: none;
  font-size: 14px;
}

SCSS


.category-tree {
  > ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    ul {
      position: relative;
      margin: 0 0 0 1em;
      padding: 0;
      list-style-type: none;
      &:before {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 0;
        height: 100%;
        content: '';
        border-left: 1px solid #fff;
      }
      li {
        position: relative;
        padding: 0 0 0 1.2em;
        &:after {
          position: absolute;
          top: 1em;
          left: 0;
          bottom: 0;
          width: .7em;
          height: 0;
          content: '';
          border-top: 1px solid #fff;
        }
        &:last-child {
          &:after {
            height: auto;
            background-color: #34495e;
          }
        }
      }
    }
    li {
      line-height: 2;
      a {
        color: #ddd;
        text-decoration: none;
        font-size: 14px;
      }
    }
  }
}

アイコンをつけてみる

FontAwesomeを使ってファイル名の前にアイコンをつけてみます。

デモ

アイコンをつけるとよりデザイン性が増します。

HTML


アイコンをつけるために <a> 要素にクラスをつけています。

CSS


.category-tree-ex > ul {
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.category-tree-ex > ul ul {
  position: relative;
  margin: 0 0 0 1em;
  padding: 0;
  list-style-type: none;
}
.category-tree-ex > ul ul:before {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 100%;
  content: '';
  border-left: 1px solid #fff;
}
.category-tree-ex > ul ul li {
  position: relative;
  padding: 0 0 0 1.2em;
}
.category-tree-ex > ul ul li:after {
  position: absolute;
  top: 1em;
  left: 0;
  bottom: 0;
  width: .7em;
  height: 0;
  content: '';
  border-top: 1px solid #fff;
}
.category-tree-ex > ul ul li:last-child:after {
  height: auto;
  background-color: #34495e;
}
.category-tree-ex > ul li {
  line-height: 2;
}
.category-tree-ex > ul li a {
  color: #ddd;
  text-decoration: none;
  font-size: 14px;
}
.category-tree-ex > ul li a:before {
  margin: 0 .55em 0 0;
  font-family: fontAwesome;
}
.category-tree-ex > ul li a.folder:before {
  content: '\f115';
}
.category-tree-ex > ul li a.excel:before {
  content: '\f1c3';
}
.category-tree-ex > ul li a.file:before {
  content: '\f016';
}
.category-tree-ex > ul li a.text:before {
  content: '\f0f6';
}
.category-tree-ex > ul li a.powerpoint:before {
  content: '\f1c4';
}
.category-tree-ex > ul li a.image:before {
  content: '\f1c5';
}
.category-tree-ex > ul li a.pdf:before {
  content: '\f1c1';
}

SCSS


.category-tree-ex {
  > ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    ul {
      position: relative;
      margin: 0 0 0 1em;
      padding: 0;
      list-style-type: none;
      &:before {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 0;
        height: 100%;
        content: '';
        border-left: 1px solid #fff;
      }
      li {
        position: relative;
        padding: 0 0 0 1.2em;
        &:after {
          position: absolute;
          top: 1em;
          left: 0;
          bottom: 0;
          width: .7em;
          height: 0;
          content: '';
          border-top: 1px solid #fff;
        }
        &:last-child {
          &:after {
            height: auto;
            background-color: #34495e;
          }
        }
      }
    }
    li {
      line-height: 2;
      a {
        color: #ddd;
        text-decoration: none;
        font-size: 14px;
        &:before {
          margin: 0 .55em 0 0;
          font-family: fontAwesome;
        }
        &.folder:before { content: '\f115' }
        &.excel:before { content: '\f1c3' }
        &.file:before { content: '\f016' }
        &.text:before { content: '\f0f6' }
        &.powerpoint:before { content: '\f1c4' }
        &.image:before { content: '\f1c5' }
        &.pdf:before { content: '\f1c1' }
      }
    }
  }
}