博主信息
博文 9
粉丝 1
评论 0
访问量 10728
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css实现带有四个圆角的table表格 2019年9月6日
江水的博客
原创
1661人浏览过

CSS制作一张带有四个圆角的表格 示例如下:


实例

<table>
        <caption>重庆巴蜀中学八年级(二班) 课表</caption>
            <thead>
                <tr >
                    <th>星期</th>
                    <th>星期一</th>
                    <th>星期二</th>
                    <th>星期三</th>
                    <th>星期四</th>
                    <th>星期五</th>
                </tr>     
            </thead>
                    <tbody>
                        <tr>
                            <td rowspan="3" >上午<br>8:30~11:50</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="2">下午<br>13:50~17:30</td>
                            <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>

运行实例 »

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

实例

/* 为表格及单元格加上边框 */
table,th,td{
    border:1px solid #444;
}
/* 将表格边框线折叠并居中显示 */
table{
    border-collapse: collapse;
    width: 800px;
    margin:0 auto;
    box-shadow: 5px 5px 8px #888;
    position: relative;
    /* 设置是否把表格边框合并为单一的边框 */
    border-collapse: separate;
    /* 设置单元格边框的距离 */
border-spacing: 0;
border-radius:10px;
}
/* 设置单元格的样式 */
th,td{
    text-align: center;
    padding:10px;
    /* border-radius:10px; */
}
/* 设置表格圆角效果 */
table th:first-of-type{
    border-top-left-radius: 10px;
}
table thead>tr:first-of-type>th:last-of-type{
    border-top-right-radius: 10px;
}
table tfoot>tr:first-of-type>td:first-of-type{
    border-bottom-left-radius: 10px;
}
table tfoot>tr:first-of-type>td:last-of-type{
    border-bottom-right-radius: 10px;
}
/* 设置表格标题样式 */
table caption{
    font-size: 1.2em;
    font-weight: bolder;
    margin-bottom: 20px;
}
table thead>tr:first-of-type{
    background-color: lightblue;
}
table tbody>tr:first-of-type>td:first-of-type{
    background-color: wheat;
}
table tbody > tr:nth-last-child(2) > td:first-of-type{
    background-color: goldenrod;
}
table tfoot>tr:last-of-type{
    background-color: lightgrey;
}

/* 为表格添加背景图片 */
table::before{
    content: "";
    width:800px;
    height: 295px;
    left: 0;
    top:48px;
    position: absolute;
    background-image: url("../image/school.jpg");
    opacity: 0.5;
    background-size:cover;
    border-radius: 10px;
}

运行实例 »

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

最终运行的一个效果图:

table.png

总结:

要想实现一个table表格带有四个圆角的效果,要将table标签的border-collapse的属性设置为separate,也是默认值,把border-spacing的值设为0,border-radius设置一个值,让后通过伪类选择器选中表格当中的四个角,设置一下圆角就实现了一个带有四个圆角效果的表格。


批改状态:合格

老师批语:你的圆角表格有问题, 文字随背影全透明了, 检查一下, 考虑到流程是正确的, 先通过
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学