博主信息
博文 7
粉丝 0
评论 1
访问量 7665
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
使用css选择器来实现表格的四角变圆角——2019.9.6
四糸乃大冒险
原创
1134人浏览过

这次对表格来一次操作,用css控制表格中的某个属性进改变。目的嘛就是为了熟悉属性选择操作。

先获得表格~

<table>
        <caption>
            <h2>勇者培训中心课程安排</h2>
        </caption>
        <thead>
            <tr>
                <th>星期</th>
                <th>星期一</th>
                <th>星期二</th>
                <th>星期三</th>
                <th>星期四</th>
                <th>星期五</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td rowspan="3">上午</td>
                <td>治疗</td>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
            </tr>
            <tr>
                <td>治疗</td>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
            </tr>
            <tr>
                <td>治疗</td>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
            </tr>
            <tr>
                <td rowspan="3">下午</td>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
                <td>治疗</td>
            </tr>
            <tr>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
                <td>治疗</td>
            </tr>
            <tr>
                <td>战斗</td>
                <td>闪避</td>
                <td>体魄</td>
                <td>意志</td>
                <td>治疗</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>备注:</td>
                <td colspan="5">还欠修女两枚金币</td>
            </tr>
        </tfoot>
    </table>

接着再用css来改变样式

table {
    border: 1px solid #444;
    border-collapse: separate;
    /*一定要设置这个属性,否则之后的圆角属性就无法修改了*/
    width: 800px;
    margin: 20px auto;
    border-radius: 10px;
    /*表格外框四角圆角*/
}
 
th,
td {
    border: 1px solid #444;
    text-align: center;
    padding: 10px;
}
 
table caption {
    font-size: 1.3rem;
    font-weight: bolder;
    margin-bottom: 15px;
}
 
table thead {
    border-radius: 10px;
}
 
table thead>tr:first-of-type {
    background-color: navajowhite;
}
 
/* 第一行的第一个tr的第一个th左上角变圆角 */
 
table thead>tr:first-of-type>th:first-of-type {
    border-top-left-radius: 10px;
}
 
/* 第一行的最后一个tr的右上角变圆角 */
 
table thead>tr:first-of-type>th:last-of-type {
    border-top-right-radius: 10px;
}
 
table tbody>tr:first-of-type>td:first-of-type {
    background-color: green;
}
 
table tbody>tr:nth-last-of-type(2)>td:first-of-type {
    background-color: royalblue;
}
 
table tfoot>tr:last-of-type {
    background-color: yellow;
}
 
/* 左下角 */
 
table tfoot>tr:last-of-type>td:first-of-type {
    border-bottom-left-radius: 10px;
}
 
/* 右下角 */
 
table tfoot>tr:last-of-type>td:last-of-type {
    border-bottom-right-radius: 10px;
}
 
table {
    box-shadow: 2px 2px 2px #888;
    position: relative;
}
 
table::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 395px;
    border-radius: 10px;
    left: 0;
    top: 105px;
    background-image: url("http://www.destiny-child.com/images/_index/bg_world_img.jpg");
    background-size: cover;
    opacity: 0.3;
}

最终出来的效果就是:

2$1O~BUIXO7Y05O)Q~D%856.png

目前看来这个选择器有点得心应手,就是不知道在其它地方可不可以用的那么顺手。

table的border-collapse: separate;也是意识的盲区,一开始还以为为什么不起作用,加了这个属性才成功修改。

至于表格这个,感觉以后可以和选择器配合拿来做些有意思的游戏~先记下了。

批改状态:合格

老师批语:表格是,最终呈现数据的是单元格, 一定要记住这点
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学