1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vivliostyle-CLIでリストをファイルツリーとして描画する

Last updated at Posted at 2022-02-23

Markdownのリストとして記述された要素を、ファイルツリーとして描画するCSSのサンプルです。
カスタムデータ属性をキャプションとして使用する方法は、テーブル要素にも応用できるかもしれません。

CSSのみで作る見やすいファイルツリーを参考にアイコンの削除、px指定をem指定に変更しました。

描画結果

スクリーンショット 2022-02-23 20.23.50.png

ソースコード

<div class="tree" data-caption="図1 ファイル構成">

* root
  * sub1
    * file1.txt
    * file2.txt
  * sub2
    * file3.txt
  * sub3
    * sub3a
      * sub3b

</div>
 .tree {
   position: relative;
   background: white;
   margin:0 0 0 2em;
   font-family: 'Roboto Mono', monospace;
   font-size: .85em;
   font-weight: 400;
   line-height: 1.5;
   color: #212529;
   border: solid 1px #666;
   padding: 1em;
 }

 .tree::after {
   content: attr(data-caption);
   text-align: center;
   bottom: -1.5em;
   width: 100%;
   position: absolute;
 }

 .tree ul {
   padding-left: 1em;
   list-style: none;
 }
 .tree ul li {
   position: relative;
   padding-top: 0.25em;
   padding-bottom: 0.25em;
   padding-left: 1em;
   box-sizing: border-box;
 }
 .tree ul li:before {
   position: absolute;
   top: 1.1em;
   left: 0;
   width: 0.7em;
   height: 1px;
   margin: auto;
   content: '';
   background-color: #666;
 }
 .tree ul li:after {
   position: absolute;
   top: 0;
   bottom: 0;
   left: 0;
   width: 1px;
   height: 100%;
   content: '';
   background-color: #666;
 }
 .tree ul li:last-child:after {
   height: 1.1em;
 }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?