数据样式

表格

定制表格

除了使用table标签绘制表格外,也可以使用样式绘制。

样式规则说明
table对应 table
table-caption对应 caption
table-row对表 tr
table-row-group对应 tbody
table-header-group对应 thead
table-footer-group对应 tfoot
.table {
    display: table;
    border: solid 1px #ddd;
}

.table nav {
    display: table-caption;
    text-align: center;
    background: black;
    color: white;
    padding: 10px;
}

.table section:nth-of-type(1) {
    font-weight: bold;
    display: table-header-group;
    background: #555;
    color: white;
}

.table section:nth-of-type(2) {
    display: table-row-group;
}

.table section:nth-of-type(3) {
    display: table-footer-group;
    background: #f3f3f3;
}

.table section ul {
    display: table-row;
}

.table section ul li {
    padding: 10px;
    display: table-cell;
    border: solid 1px #ddd;
}
<article class="table">
    <nav>在线文档</nav>
    <section>
        <ul>
            <li>标题</li>
            <li>说明</li>
        </ul>
    </section>
    <section>
        <ul>
            <li>mkimq</li>
            <li>mkimq.com</li>
        </ul>
        <ul>
            <li>node</li>
            <li>mkimq.com</li>
        </ul>
    </section>
    <section>
        <ul>
            <li>不断更新文档</li>
            <li>一起加油</li>
        </ul>
    </section>
</article>

表格标题

通过caption-side可以设置标题位置,值可以设置为[top | bootom]。

内容对齐

  1. 水平对齐使用text-align文本对齐规则

  2. 垂直对齐使用vertical-align处理

属性说明
top顶对齐
middle垂直居中
bottom底部对齐

颜色设置

为表格设置颜色与普通标签相似,可以为[table | thead | tbody | caption | tfoot | tr | td]设置颜色样式。

边框间距

设置单元格间距,设置间距上下10px ,左右 50px。

table {
    border-spacing: 50px 10px;
}

边框合并

默认表格边框间是有间距的,以下示例将边框合并形成细线表格。

table {
    border-collapse: collapse;
}

隐藏单元格

table {
    empty-cells: hide;
}

无边框表格

table {
    border: none;
    border-collapse: collapse;
}

table td {
    border: none;
    border-right: solid 1px #ddd;
    border-bottom: solid 1px #ddd;
}

table tr:first-child td {
    border-top: solid 1px #ddd;
}

table td:last-child {
    border-right: none;
}

数据表格

可以为表格元素使用伪类控制样式,下例中使用 hover 伪类样式

table,
td {
    border: none;
    font-size: 14px;
    border-collapse: collapse;
}

table tr:hover {
    background: #ddd;
    cursor: pointer;
}

table td {
    border-top: solid 1px #ccc;
    padding: 10px;
}

列表

列表符号

使用 list-style-type 来设置列表样式,规则是继承的,所以在ul 标签上设置即可。

描述
none无标记。
disc默认。标记是实心圆。
circle标记是空心圆。
square标记是实心方块。
decimal标记是数字。
decimal-leading-zero0开头的数字标记。(01, 02, 03, 等。)
lower-roman小写罗马数字(i, ii, iii, iv, v, 等。)
upper-roman大写罗马数字(I, II, III, IV, V, 等。)
lower-alpha小写英文字母The marker is lower-alpha (a, b, c, d, e, 等。)
upper-alpha大写英文字母The marker is upper-alpha (A, B, C, D, E, 等。)
lower-greek小写希腊字母(alpha, beta, gamma, 等。)
lower-latin小写拉丁字母(a, b, c, d, e, 等。)
upper-latin大写拉丁字母(A, B, C, D, E, 等。)
hebrew传统的希伯来编号方式
armenian传统的亚美尼亚编号方式
georgian传统的乔治亚编号方式(an, ban, gan, 等。)
cjk-ideographic简单的表意数字
hiragana标记是:a, i, u, e, o, ka, ki, 等。(日文片假名)
katakana标记是:A, I, U, E, O, KA, KI, 等。(日文片假名)
hiragana-iroha标记是:i, ro, ha, ni, ho, he, to, 等。(日文片假名)
katakana-iroha标记是:I, RO, HA, NI, HO, HE, TO, 等。(日文片假名)

自定义列表样式

ul li {
    /* list-style-image: url(xj-small.png);
    list-style-image: radial-gradient(10px 10px, red, black); */
    list-style-image: linear-gradient(45deg, red, black);
}

符号位置

控制符号显示在内容外面还是内部

选项说明
inside内部
outside外部
ul {
    list-style-position: inside;
}

组合定义

可以一次定义列表样式

ul {
    list-style: circle inside;
}

背景符号

ul li {
    background: url('small.png') no-repeat 0 6px;
    background-size: 10px 10px;
    list-style-position: inside;
    list-style: none;
    text-indent: 15px;
}

追加内容

基本使用

使用伪类 ::before 向前添加内容,使用 ::after 向后面添加内容。

a::after {
  content: "hello world";
}

提取属性

使用属性值添加内容,可以使用标准属性与自定义属性。

a::after {
    content: attr(href);
}
贡献者: mankueng