官术网_书友最值得收藏!

Styling a file list

The file list will be represented as a table, but we will build it out of an unordered list. The./index.html file contains the following code:

<main class="l-main__file-list file-list"> 
<nav>
<ul>
<li class="file-list__li file-list__head">
<span class="file-list__li__name">Name</span>
<span class="file-list__li__size">Size</span>
<span class="file-list__li__time">Modified</span>
</li>
<li class="file-list__li">
<span class="file-list__li__name">index.html</span>
<span class="file-list__li__size">1.71 KB</span>
<span class="file-list__li__time">3/3/2017, 15:44:19</span>
</li>
<li class="file-list__li">
<span class="file-list__li__name">package.json</span>
<span class="file-list__li__size">539 B</span>
<span class="file-list__li__time">3/3/2017, 17:53:19</span>
</li>
</ul>
</nav>
</main>

In fact, here Grid Layout (https://www.w3.org/TR/css3-grid-layout/) would probably suit better; however, at the time of writing, this CSS module was not yet available in NW.js. So, we go on again with Flexbox:

./assets/css/Component/file-list.css

.file-list { 
background-color: var(--filelist-bg-color);
color: var(--filelist-fg-color);
cursor: pointer;
}

.file-list__li {
display: flex;
flex-flow: row nowrap;
}

.file-list__li:not(.file-list__head){
cursor: pointer;
}
.file-list__li:not(.file-list__head):hover {
color: var(--filelist-fg-hover-color);
}
.file-list__li > * {
flex: 1 1 auto;
padding: 0.8em 0.8em;
overflow: hidden;
}

.file-list__li__name {
white-space: nowrap;
text-overflow: ellipsis;
width: 50%;
}
.file-list__li__time {
width: 35%;
}
.file-list__li__size {
width: 15%;
}

I believe that everything is clear with the preceding code, except that you might not be familiar with the pseudo-class :not(). I want to change the color and mouse cursor on hover for all the file list items, except the table header. So, I achieve it with a selector that can be read like any .file-list__li that is not .file-list__head.

The following assignment goes to the definitions file:

./assets/css/Base/definitions.css

--filelist-fg-hover-color: #d64937; 

As we run the application we can see the table with the file list:

主站蜘蛛池模板: 呈贡县| 万源市| 济源市| 杂多县| 新竹市| 乌什县| 大埔区| 雅江县| 邳州市| 克山县| 新宾| 平昌县| 兴化市| 读书| 蕉岭县| 托克托县| 景谷| 沾化县| 永年县| 大冶市| 涟源市| 巩留县| 尤溪县| 米脂县| 长治市| 阿荣旗| 清流县| 崇阳县| 东兰县| 苗栗县| 晋州市| 繁昌县| 临湘市| 惠东县| 武鸣县| 都匀市| 会同县| 灵川县| 淮南市| 翼城县| 博兴县|