博主信息
博文 23
粉丝 0
评论 0
访问量 17358
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
20190906 作业
王长中的博客
原创
538人浏览过

用css控制表格中的样式:

实例

<title>css圆角表格</title>
    <style>
        /*设置表格大小边框*/
        table{
            width: 500px;
            height: 400px;
            margin:0 auto;
            text-align:center;
            border:1px solid black;
            border-radius:10px;
            box-shadow:3px 3px gray ;
        }
        table{
            background-image: url("http://img3***gtn.bdimg.com/it/u=2568114326,1575192997&fm=26&gp=0.jpg");
            background-size: cover;

        }
        /*设置单元格背景色*/
        table tbody tr:nth-of-type(1)> td:first-of-type,
        table tbody tr:nth-of-type(5)> td:first-of-type,
        table tbody tr:nth-of-type(9)> td:first-of-type {
            background-color:lightseagreen;
            opacity: 0.5;
        }
        table tbody>tr:nth-of-type(1)>td,
        table tbody>tr:nth-of-type(2)>td,
        table tbody>tr:nth-of-type(3)>td,
        table tbody>tr:nth-of-type(5)>td,
        table tbody>tr:nth-of-type(6)>td,
        table tbody>tr:nth-of-type(7)>td,
        table tbody>tr:nth-of-type(9)>td,
        table tbody>tr:nth-of-type(10)>td,
        table tbody>tr:nth-of-type(11)>td{
            background-color:lightsalmon;
            opacity: 0.5;
        }
        /*设置表格标题格式*/
        caption{
            font-size:1.5rem;
            font-weight:bolder;
            margin-bottom:15px;
        }

        /*设置表头背景色*/
        table thead tr{
            background-color: lightcyan;
        }
        /*设置小计行背景色*/
        .color{
            font-weight:bolder;
            background-color: lightgrey;
        }
        /*设置总计行背景色*/
        table tfoot tr{
            font-size:1.3rem;
            font-weight:bolder;
            background-color: lightblue;
        }
        /* 设置表格圆角 */

        table thead tr:nth-of-type(1)>th:nth-of-type(1) {
            border-radius: 10px 0 0 0;
        }

        table thead tr:nth-of-type(1)>th:nth-of-type(7) {
            border-radius: 0 10px 0 0;
        }

        table tfoot tr:nth-of-type(1)>td:nth-of-type(1) {
            border-radius: 0 0 0 10px;
        }

        table tfoot tr:last-of-type>td:last-of-type {
            border-radius: 0 0 10px 0;
        }

    </style>
</head>

<body>
<table>
    <caption>水果销量表</caption>
    <thead>
    <tr>
        <th>省份</th>
        <th>江苏</th>
        <th>山东</th>
        <th>广东</th>
        <th>北京</th>
        <th>上海</th>
        <th>天津</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td rowspan="3">苹果</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>

    </tr>
    <tr>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr class="color">
        <td>小计</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
    </tr>
    <tr>
        <td rowspan="3">香蕉</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr>

        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr class="color">
        <td>小计</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
    </tr>
    <tr>
        <td rowspan="3">哈蜜瓜</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
        <td>100</td>
    </tr>
    <tr class="color">
        <td>小计</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
        <td>300</td>
    </tr>

    </tbody>
    <tfoot>
    <tr>
        <td>总计</td>
        <td>900</td>
        <td>900</td>
        <td>900</td>
        <td>900</td>
        <td>900</td>
        <td>900</td>
    </tr>
    </tfoot>
</table>
</body>

运行实例 »

点击 "运行实例" 按钮查看在线实例

效果图:

XIE]9U]H5)){5[~QUOU7HW6.png


总结:

通过使用各种选择器,可以用css设置表格的大小,字体、背景色等样式。表格背景填充图片时,图片会重复,可以通过设置background-size来进行调整。

批改状态:合格

老师批语:实际上你的作业并没有完成, 表格制作 是有问题的 .... 可能你也发现了...完了再改进一下, 圆角没有做完
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学