css3表格练习

1.效果图

2.html

html 复制代码
<div class="line">

    </div>
    <h3>获奖名单</h3>
    <!-- 表格 cellspacing内边距 cellpadding外边距-->
    <table  cellspacing="0" cellpadding="0" >
        <!-- thead表头 -->
        <thead>
            <tr>
                <td>中奖用户</td>
                <td>PR排名</td>
                <td>具体奖品</td>
            </tr>
        </thead>    
        <!-- tbody表体 -->
        <tbody>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
            <tr>
                <td>王振民</td>
                <td>1</td>
                <td>
                    <div>一年学费+</div>
                    <div class="warp">特别礼品</div>
                </td>
            </tr>
        </tbody>
        <!-- tfoot表尾 -->
        <tfoot>
            <!-- <tr>
                <td>总计</td>
                <td colspan="2">共100名</td>
            </tr> -->
        </tfoot>
    </table>

3.css

css 复制代码
*{
    padding: 0;
    margin: 0;
    list-style-type: none;
}
.line{
	width: 330px;
	height: 1px;
	border-top: 1px solid #7ef805;
	margin: 0 auto;
	margin-top: 50px;
}
h3{
	width: 100px;
	text-align: center;
    /* 关键点,利用定位让文字居中 */
	position: relative;
	margin: 0 auto;
	bottom: 14px;
	background-color: white;
	color: #7ef805;
}
table{
    width: 330px;
    /* margin: 0 auto;居中 */
    margin: 0 auto; 
    text-align: center;
    vertical-align: middle;
}

table tr td{
    /* width: 10%; */
    height: 50px;
}
/* 去除表格四周边框 */
table td{
    border: 1px solid blue;
    /* 上边框和左边框为0 */
    border-top: 0;
    border-left: 0;
}
table td:nth-child(3){
    border-right: 0;
}
/* 站在父元素的角度上选择最后一个子元素 */
table tbody tr:last-child td{
    border-bottom: 0;
}
thead{
    background-color: #7ef805;
    color: white;
}
.warp{
    /* font-size: 10px; */
    font-weight: bolder;
}
/* 隔行变色 */
tbody tr:nth-child(odd){
    background-color: #7ef805;
}
tbody tr:nth-child(even){
    background-color: red;
}
tbody tr{
    border: 1px solid red;
}
相关推荐
Nan_Shu_6149 小时前
Web前端面试题(2)
前端
知识分享小能手9 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
2501_9181269110 小时前
用html5写一个flappybird游戏
css·游戏·html5
蚂蚁RichLab前端团队10 小时前
🚀🚀🚀 RichLab - 花呗前端团队招贤纳士 - 【转岗/内推/社招】
前端·javascript·人工智能
孩子 你要相信光11 小时前
css之一个元素可以同时应用多个动画效果
前端·css
huangql52011 小时前
npm 发布流程——从创建组件到发布到 npm 仓库
前端·npm·node.js
Days205011 小时前
LeaferJS好用的 Canvas 引擎
前端·开源
小白菜学前端11 小时前
vue2 常用内置指令总结
前端·vue.js
林_深时见鹿11 小时前
Vue + ElementPlus 自定义指令控制输入框只可以输入数字
前端·javascript·vue.js
椒盐螺丝钉11 小时前
Vue组件化开发介绍
前端·javascript·vue.js