その中に<ul>
要素が<li>
あります。リスト項目には次のいずれかがあります。
<li class="folder">
<!-- or... -->
<li class="file">
それぞれの中に入れ子になってfolder's
いるcolor-label
.
<li class="folder">
Folder 1
<i class="blue"></i>
</li>
jQuery を使用して、すべての<li class="folder">
リスト項目を動的に調べてラベルを見つけ、次のフォルダー カラー ラベルが見つかるまで各兄弟<i class="color">
にクラスを適用し、すべての項目が適切な色になるまでプロセスを繰り返す必要があります。フォルダのクラス。<li class="file">
<li>
color-label
以下に例を示します。
.nextUntil()
jquery メソッドを使用しようとしましたが、最良の結果が得られませんでした。これが私のコードです:
https://jsfiddle.net/5c11sqL5/
<nav class="directory">
<h1 class="title">Directory</h1>
<ul class="container">
<!-- Folder 1 -->
<li class="folder">Folder 1 <i class="blue"></i></li>
<li class="file">File 1</li>
<li class="file">File 2</li>
<li class="file">File 3</li>
<!-- Folder 2 -->
<li class="folder">Folder 2 <i class="green"></i></li>
<li class="file">File 1</li>
<li class="file">File 2</li>
<li class="file">File 3</li>
<!-- Folder 3 -->
<li class="folder">Folder 3 <i class="gray"></i></li>
<li class="file">File 1</li>
<li class="file">File 2</li>
<li class="file">File 3</li>
</ul>
</nav>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Courier New", Courier, monospace;
}
/* Directory */
.directory {
display: flex;
flex-direction: column;
background: #ccc;
width: 240px;
height: 100vh;
}
.directory .title {
letter-spacing: 3px;
text-transform: uppercase;
opacity: .07;
text-align: center;
margin: 1rem 0 0;
}
.directory .container {
list-style: none;
}
/* Folder and Files */
.folder {
font-weight: bold;
font-size: 1rem;
position: relative;
padding: 0 0 0 1rem;
margin: 1rem 0 0;
}
.file {
font-size: .8rem;
padding: 0 0 0 1rem;
}
/* Colors */
.blue,
.green,
.gray {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 5px;
display: block;
}
.blue {
background: rgba(0, 194, 224, 1);
}
.green {
background: rgba(81, 232, 152, 1);
}
.gray {
background: rgba(131, 140, 145, 1);
}