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

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:

主站蜘蛛池模板: 海城市| 故城县| 汤阴县| 集贤县| 南阳市| 梓潼县| 美姑县| 灵璧县| 额济纳旗| 合水县| 长春市| 安泽县| 杭锦旗| 额尔古纳市| 苏尼特右旗| 烟台市| 镇远县| 旅游| 新乐市| 甘肃省| 正宁县| 双峰县| 永德县| 清河县| 任丘市| 克拉玛依市| 镇巴县| 阿拉善盟| 陆良县| 江门市| 镶黄旗| 博湖县| 东海县| 册亨县| 冷水江市| 游戏| 广宗县| 禹城市| 手游| 宜黄县| 武鸣县|