美文网首页
table-cell实现制表格

table-cell实现制表格

作者: 鲁大师666 | 来源:发表于2017-07-21 18:27 被阅读0次

<h2>一、CSS display属性的表格布局相关属性的解释:</h2>
<ul>
<li>table 此元素会作为块级表格来显示(类似 <table>),表格前后带有换行符。</li>
<li>table-row-group 此元素会作为一个或多个行的分组来显示(类似 <tbody>)。</li>
<li>table-header-group 此元素会作为一个或多个行的分组来显示(类似 <thead>)。</li>
<li>table-footer-group 此元素会作为一个或多个行的分组来显示(类似 <tfoot>)。</li>
<li>table-row 此元素会作为一个表格行显示(类似 <tr>)。</li>
<li>table-column-group 此元素会作为一个或多个列的分组来显示(类似 <colgroup>)。</li>
<li>table-column 此元素会作为一个单元格列显示(类似 <col>)</li>
<li>table-cell 此元素会作为一个表格单元格显示(类似 <td> 和 <th>)</li>
<li>table-caption 此元素会作为一个表格标题显示(类似 <caption>)</li>
</ul>

<h2>二、示例代码:</h2>
<h3>1.普通表格</h3>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>display普通表格</title>
<style type="text/css">
.table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}
.table {display: table; width: 80%; border-collapse: collapse;}
.table-tr {display: table-row; height: 30px;}
.table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}
.table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}
</style>
</head>
<body>
    <div class="table">
        <div class="table-tr">
            <div class="table-th">省份/直辖市</div>
            <div class="table-th">GDP(亿元)</div>
            <div class="table-th">增长率</div>
        </div>
        <div class="table-tr">
            <div class="table-td">广东</div>
            <div class="table-td">72812</div>
            <div class="table-td">8.0%</div>
        </div>
        <div class="table-tr">
            <div class="table-td">河南</div>
            <div class="table-td">37010</div>
            <div class="table-td">8.3%</div>
        </div>
        <div class="table-tr">
            <div class="table-td">江苏</div>
            <div class="table-td">70116</div>
            <div class="table-td">8.5%</div>
        </div>
    </div>
</body>
</html>

<h3>2.行合并表格</h3>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>基于display列合并表格</title>
<style type="text/css">
.table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}
.table {display: table; width: 80%; border-collapse: collapse;}

.table-tr {display: table-row; height: 30px;}
.table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}
.table-td {display: table-cell; height: 100%;}

.sub-table {width: 100%;height: 100%;display: table;}
.sub-table-tr {display: table-row; height: 100%;}
.sub-table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}

</style>
</head>
<body>

<div class="table">
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="table-th" style="width: 40%;">省份/直辖市</div>
                    <div class="table-th" style="width: 30%;">GDP(亿元)</div>
                    <div class="table-th" style="width: 30%;">增长率</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 40%;">广东</div>
                    <div class="sub-table-td" style="width: 30%;">72812</div>
                    <div class="sub-table-td" style="width: 30%;">8.0%</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 40%;">河南</div>
                    <div class="sub-table-td" style="width: 30%;">37010</div>
                    <div class="sub-table-td" style="width: 30%;">8.3%</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 40%;">江苏</div>
                    <div class="sub-table-td" style="width: 30%;">70116</div>
                    <div class="sub-table-td" style="width: 30%;">8.5%</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 70%;">各省/直辖市GDP平均增长率</div>
                    <div class="sub-table-td" style="width: 30%;">8.26%</div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<h3>3.列合并表格</h3>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>基于display的行合并表格</title>
<style type="text/css">
.table, .table * {margin: 0 auto; padding: 0;font-size: 14px;font-family: Arial, 宋体, Helvetica, sans-serif;}
.table {display: table; width: 80%; border-collapse: collapse;}

.table-tr {display: table-row; height: 30px;}
.table-th {display: table-cell;font-weight: bold;height: 100%;border: 1px solid gray;text-align: center;vertical-align: middle;background-color:#E5E5E5;}
.table-td {display: table-cell; height: 100%;}

.sub-table {width: 100%;height: 100%;display: table;}
.sub-table-tr {display: table-row; height: 100%;}
.sub-table-td {display: table-cell; height: 100%;border: 1px solid gray; text-align: center;vertical-align: middle;}

</style>
</head>
<body>

<div class="table">
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="table-th" style="width: 40%;">省份/直辖市</div>
                    <div class="table-th" style="width: 30%;">GDP(亿元)</div>
                    <div class="table-th" style="width: 30%;">增长率</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 40%;">广东</div>
                    <div class="sub-table-td" style="width: 30%;">72812</div>
                    <div class="sub-table-td" style="width: 30%;">8.0%</div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr" style="height:60px;">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 40%; border: none;">
                        <div class="sub-table">
                            <div class="sub-table-tr" style="height:50%;">
                                <div class="sub-table-td" style="width: 100%; height:50%;">
                                    河南
                                </div>
                            </div>
                            <div class="sub-table-tr" style="height:50%;">
                                <div class="sub-table-td" style="width: 100%; height:50%;">
                                    江苏
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="sub-table-td" style="width: 30%;border: none;">
                        <div class="sub-table">
                            <div class="sub-table-tr" style="height:50%;">
                                <div class="sub-table-td" style="width: 100%; height:50%;">
                                    37010
                                </div>
                            </div>
                            <div class="sub-table-tr" style="height:50%;">
                                <div class="sub-table-td" style="width: 100%; height:50%;">
                                    70116
                                </div>
                            </div>
                        </div>
                    
                    </div>
                    
                    <div class="sub-table-td" style="width: 30%;border: none;">
                        <div class="sub-table">
                            <div class="sub-table-tr">
                                <div class="sub-table-td" style="width: 100%;">
                                    8.4%
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="table-tr">
        <div class="table-td">
            <div class="sub-table">
                <div class="sub-table-tr">
                    <div class="sub-table-td" style="width: 70%;">各省/直辖市GDP平均增长率</div>
                    <div class="sub-table-td" style="width: 30%;">8.26%</div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

相关文章

  • html+css小结

    1.布局 a.实现等高div布局利用display:table-cell;系列的属性实现,因为表格是自适应的。 注...

  • table-cell实现制表格

    一、CSS display属性的表格布局相关属性的解释: table 此元素会作为块级表格来显示(类似 ...

  • display:table-cell的应用

    display:table-cell:指让标签元素以表格单元格的形式呈现,类似于td(ie8以上支持) 1、实现文...

  • css 移动端布局(一)

    布局方式总结:float(浮动) 、 position(定位i) 、table-cell(转表格)、flex(弹性...

  • vue样式

    表格对齐 body .el-table th.gutter { display:table-cell !impor...

  • 垂直居中

    方法一 这个方法把一些 div的显示方式设置为表格table-cell,因此我们可以使用表格的 vertical-...

  • 你熟悉的display:table-cell

    1. dispaly:table-cell属性说明 dispaly:table-call属性是让标签以表格形式呈现...

  • CSS无敌居中

    无需知道宽高 CSS transform 使用display:table-cell来居中 对于那些不是表格的元素,...

  • 2019-08-25

    布局 说法一 浮动布局 绝对定位布局 Flex布局 Table-cell表格布局 网格布局 说法二 静态布局 流式...

  • CSS-Tricks(三):垂直居中的四种方法

    1. display:table; 和 display:table-cell;实现动态垂直居中 思路:父级元素使用...

网友评论

      本文标题:table-cell实现制表格

      本文链接:https://www.haomeiwen.com/subject/ekgekxtx.html