CSS ol/ul li 建立章節目錄 (css ol/ul li decoration)

css li也可以製作有階層的章節目錄
20160927

html

<ul>
  <li>cheapter 1
    <ul>
       <li>cheapter 1.1</li>
       <li>cheapter 1.2</li>
    </ul>
  </li>
  <li>cheapter 2
    <ul>
       <li>cheapter 2.1</li>
       <li>cheapter 2.2</li>
    </ul>
  </li>
</ul>

CSS

ul {
	list-style-type: none;
	counter-reset: cheapter;
	/*counter-reset: cheapter(自定變數);*/
}
ul > li {
	counter-increment: cheapter;
}
ul > li:before {
	content: counter(cheapter);
}
ul ul {
	list-style-type: none;
	counter-reset: unit;/*counter-reset: unit(自定變數);*/
}
ul ul > li {
	counter-increment: unit;
}
ul ul > li:before {
	content: counter(cheapter) "." counter(unit);
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *