1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-06 22:26:33 +02:00

feat: Tree diagram

This commit is contained in:
Phuoc Nguyen
2022-09-20 09:55:25 +07:00
parent 6d98b09f7b
commit e799bba2e9
12 changed files with 251 additions and 339 deletions

View File

@@ -0,0 +1,28 @@
<div class="tree-diagram">
<ul>
<li class="tree-diagram__root">
{% square %}
<ul>
<li>
{% square %}
<ul>
<li>
{% square %}
</li>
</ul>
</li>
<li>
{% square %}
<ul>
<li>
{% square %}
</li>
<li>
{% square %}
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

View File

@@ -277,6 +277,12 @@ eleventyExcludeFromCollections: true
<div class="pattern__title">Timeline</div>
</a>
</div>
<div class="pattern__item">
<a class="pattern__link" href="/tree-diagram/">
<div class="pattern__cover">{% include "patterns/tree-diagram.njk" %}</div>
<div class="pattern__title">Tree diagram</div>
</a>
</div>
<div class="pattern__item">
<a class="pattern__link" href="/video-background/">
<div class="pattern__cover">{% include "patterns/video-background.njk" %}</div>

132
contents/tree-diagram.md Normal file
View File

@@ -0,0 +1,132 @@
---
layout: layouts/post.njk
title: Tree diagram
description: Create a tree diagram with CSS
keywords: css sitemap, css tree diagram
---
## HTML
```html
<div class="tree-diagram">
<ul>
<li>
<!-- Content -->
...
<!-- Sub items -->
<ul>
<li>
<!-- Content -->
...
<!-- Sub items -->
<ul>
<li>...</li>
<li>...</li>
...
</ul>
</li>
<li>...</li>
...
</ul>
</li>
<!-- Repeat other items -->
...
</ul>
</div>
```
## CSS
```css
.tree-diagram ul {
display: flex;
position: relative;
/* Reset */
list-style-type: none;
margin: 0;
padding: 1rem 0.5rem 0rem 0.5rem;
}
.tree-diagram ul ul::before {
border-right: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li {
padding: 1rem 0.5rem 0rem 0.5rem;
position: relative;
/* Center the content */
align-items: center;
display: flex;
flex-direction: column;
}
.tree-diagram li::before {
border-right: 1px solid #d1d5db;
border-top: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li::after {
border-top: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 0;
/* Size */
width: 50%;
}
.tree-diagram li:first-child::before,
.tree-diagram li:last-child::after {
/* Remove the top of border from the first and last items */
border-top: none;
}
/* Add a root item if you want */
li.tree-diagram__root::before {
border-right: none;
}
```
You can add a root item to the tree:
```html
<div class="tree-diagram">
<ul>
<li class="tree-diagram__root">
...
</li>
</ul>
</div>
```
{% demo %}
{% include "patterns/tree-diagram.njk" %}
{% enddemo %}

View File

@@ -1,197 +0,0 @@
import * as React from 'react';
import Head from 'next/head';
import { Spacer } from '@1milligram/design';
import { RelatedPatterns } from '../../components/RelatedPatterns';
import { Pattern } from '../../constants/Pattern';
import { PatternLayout } from '../../layouts/PatternLayout';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Square from '../../placeholders/Square';
const Details: React.FC<{}> = () => {
return (
<PatternLayout pattern={Pattern.TreeDiagram}>
<Head>
<meta name="description" content="Create a tree diagram with CSS" />
<meta name="og:description" content="Create a tree diagram with CSS" />
<meta name="twitter:description" content="Create a tree diagram with CSS" />
<meta name="keywords" content="css sitemap, css tree diagram" />
</Head>
<BrowserFrame
html={`
<div class="tree-diagram">
<ul>
<li>
<!-- Content -->
...
<!-- Sub items -->
<ul>
<li>
<!-- Content -->
...
<!-- Sub items -->
<ul>
<li>...</li>
<li>...</li>
...
</ul>
</li>
<li>...</li>
...
</ul>
</li>
<!-- Repeat other items -->
...
</ul>
</div>
`}
css={`
.tree-diagram ul {
display: flex;
position: relative;
/* Reset */
list-style-type: none;
margin: 0;
padding: 1rem 0.5rem 0rem 0.5rem;
}
.tree-diagram ul ul::before {
border-right: 1px solid rgba(0, 0, 0, 0.3);
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li {
padding: 1rem 0.5rem 0rem 0.5rem;
position: relative;
/* Center the content */
align-items: center;
display: flex;
flex-direction: column;
}
.tree-diagram li::before {
border-right: 1px solid rgba(0, 0, 0, 0.3);
border-top: 1px solid rgba(0, 0, 0, 0.3);
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li::after {
border-top: 1px solid rgba(0, 0, 0, 0.3);
content: '';
/* Position */
position: absolute;
top: 0;
right: 0;
/* Size */
width: 50%;
}
.tree-diagram li:first-child::before,
.tree-diagram li:last-child::after {
/* Remove the top of border from the first and last items */
border-top: none;
}
/* Add a root item if you want */
li.tree-diagram__root::before {
border-right: none;
}
`}
>
<div
style={{
alignItems: 'center',
display: 'flex',
height: '100%',
justifyContent: 'center',
padding: '0.5rem',
}}
>
<div className="tree-diagram">
<ul>
<li className="tree-diagram__root">
<Square size="2.5rem" />
<ul>
<li>
<Square size="2rem" />
<ul>
<li>
<Square size="1.5rem" />
</li>
</ul>
</li>
<li>
<Square size="2rem" />
<ul>
<li>
<Square size="1.5rem" />
<ul>
<li>
<Square size="1rem" />
</li>
<li>
<Square size="1rem" />
</li>
<li>
<Square size="1rem" />
</li>
</ul>
</li>
<li>
<Square size="1.5rem" />
</li>
<li>
<Square size="1.5rem" />
<ul>
<li>
<Square size="1rem" />
</li>
<li>
<Square size="1rem" />
</li>
</ul>
</li>
</ul>
</li>
<li>
<Square size="2rem" />
</li>
</ul>
</li>
</ul>
</div>
</div>
</BrowserFrame>
<Spacer size="extraLarge" />
<RelatedPatterns patterns={[Pattern.FolderStructure]} />
</PatternLayout>
);
};
export default Details;

View File

@@ -1,129 +0,0 @@
import * as React from 'react';
import Frame from '../../placeholders/Frame';
import Square from '../../placeholders/Square';
const Cover: React.FC<{}> = () => {
return (
<Frame>
<div
style={{
alignItems: 'center',
display: 'flex',
height: '100%',
justifyContent: 'center',
padding: '0.5rem',
}}
>
<div style={{}}>
<div
style={{
display: 'flex',
justifyContent: 'center',
padding: '0rem 0.5rem 1rem 0.5rem',
position: 'relative',
}}
>
<div
style={{
borderRight: '1px solid rgba(0, 0, 0, 0.3)',
height: '1rem',
position: 'absolute',
right: '50%',
bottom: 0,
width: '50%',
}}
/>
<div
style={{
backgroundColor: 'rgba(0, 0, 0, 0.3)',
borderRadius: '0.25rem',
height: '1rem',
width: '1rem',
}}
/>
</div>
<div
style={{
display: 'flex',
flexWrap: 'nowrap',
}}
>
<div
style={{
padding: '1rem 0.5rem 0 0.5rem',
position: 'relative',
}}
>
<div
style={{
borderRight: '1px solid rgba(0, 0, 0, 0.3)',
height: '1rem',
position: 'absolute',
right: '50%',
top: 0,
width: '50%',
}}
/>
<div
style={{
backgroundColor: 'rgba(0, 0, 0, 0.3)',
borderRadius: '0.25rem',
height: '1rem',
width: '1rem',
}}
/>
<div
style={{
borderTop: '1px solid rgba(0, 0, 0, 0.3)',
height: '1rem',
left: '50%',
position: 'absolute',
top: 0,
width: '50%',
}}
/>
</div>
<div
style={{
padding: '1rem 0.5rem 0 0.5rem',
position: 'relative',
}}
>
<div
style={{
borderRight: '1px solid rgba(0, 0, 0, 0.3)',
height: '1rem',
position: 'absolute',
right: '50%',
top: 0,
width: '50%',
}}
/>
<div
style={{
backgroundColor: 'rgba(0, 0, 0, 0.3)',
borderRadius: '0.25rem',
height: '1rem',
width: '1rem',
}}
/>
<div
style={{
borderTop: '1px solid rgba(0, 0, 0, 0.3)',
height: '1rem',
position: 'absolute',
right: '50%',
top: 0,
width: '50%',
}}
/>
</div>
</div>
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -55,6 +55,7 @@
@import './patterns/teardrop';
@import './patterns/three-dimensions-card';
@import './patterns/timeline';
@import './patterns/tree-diagram';
@import './patterns/triangle-buttons';
@import './patterns/video-background';
@import './patterns/voting';

View File

@@ -0,0 +1,72 @@
.tree-diagram ul {
display: flex;
position: relative;
/* Reset */
list-style-type: none;
margin: 0;
padding: 1rem 0.5rem 0rem 0.5rem;
}
.tree-diagram ul ul::before {
border-right: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li {
padding: 1rem 0.5rem 0rem 0.5rem;
position: relative;
/* Center the content */
align-items: center;
display: flex;
flex-direction: column;
}
.tree-diagram li::before {
border-right: 1px solid #d1d5db;
border-top: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 50%;
/* Size */
height: 1rem;
width: 50%;
}
.tree-diagram li::after {
border-top: 1px solid #d1d5db;
content: '';
/* Position */
position: absolute;
top: 0;
right: 0;
/* Size */
width: 50%;
}
.tree-diagram li:first-child::before,
.tree-diagram li:last-child::after {
/* Remove the top of border from the first and last items */
border-top: none;
}
/* Add a root item if you want */
li.tree-diagram__root::before {
border-right: none;
}

View File

@@ -1,5 +1,5 @@
.circle {
background: rgba(0, 0, 0, .3);
background: #d1d5db;
border-radius: 9999px;
height: var(--circle-size);
width: var(--circle-size);

View File

@@ -1,5 +1,5 @@
.line {
background: rgba(0, 0, 0, 0.3);
background: #d1d5db;
}
.line--hor {
height: 1px;

View File

@@ -1,5 +1,5 @@
.rectangle {
background: rgba(0, 0, 0, .3);
background: #d1d5db;
border-radius: 0.25rem;
}
.rectangle--hor {

View File

@@ -1,6 +1,5 @@
.square {
background: rgba(0, 0, 0, 0.3);
border-radius: 0.25rem;
background: #d1d5db;
height: var(--square-size);
width: var(--square-size);
}

View File

@@ -4,35 +4,35 @@
width: 0;
}
.triangle--t {
border-color: transparent transparent rgba(0, 0, 0, .3) transparent;
border-color: transparent transparent #d1d5db transparent;
border-width: 0 var(--triangle-size) var(--triangle-size) var(--triangle-size);
}
.triangle--r {
border-color: transparent transparent transparent rgba(0, 0, 0, .3);
border-color: transparent transparent transparent #d1d5db;
border-width: var(--triangle-size) 0 var(--triangle-size) 1rem;
}
.triangle--b {
border-color: rgba(0, 0, 0, .3) transparent transparent transparent;
border-color: #d1d5db transparent transparent transparent;
border-width: var(--triangle-size) var(--triangle-size) 0 var(--triangle-size);
}
.triangle--l {
border-color: transparent rgba(0, 0, 0, .3) transparent transparent;
border-color: transparent #d1d5db transparent transparent;
border-width: var(--triangle-size) 1rem var(--triangle-size) 0;
}
.triangle--tr {
border-color: transparent rgba(0, 0, 0, .3) transparent transparent;
border-color: transparent #d1d5db transparent transparent;
border-width: 0 var(--triangle-size) var(--triangle-size) 0;
}
.triangle--br {
border-color: transparent transparent rgba(0, 0, 0, .3) transparent;
border-color: transparent transparent #d1d5db transparent;
border-width: 0 0 var(--triangle-size) var(--triangle-size);
}
.triangle--bl {
border-color: transparent transparent transparent rgba(0, 0, 0, .3);
border-color: transparent transparent transparent #d1d5db;
border-width: var(--triangle-size) 0 0 var(--triangle-size);
}
.triangle--tl {
border-color: rgba(0, 0, 0, .3) transparent transparent transparent;
border-color: #d1d5db transparent transparent transparent;
border-width: var(--triangle-size) var(--triangle-size) 0 0;
}
.triangle--sm {