学习目标
- 盒子模型的4个组成部分
- 利用边框复合写法给元素添加边框
- 计算盒子的实际大小
- 给盒子设置圆角边框
- 给盒子添加阴影
- 给文字添加阴影
页面学习三大核心
盒子模型
- CSS 盒子模型本质上是一个封装周围 HTML元素(边框、内外边距和实际内容)的盒子
- 组成部分
属性 |
含义 |
border |
边框 |
content |
内容 |
padding |
内边距 |
margin |
外边距 |
边框
- border属性 设置元素的边框
- 组成部分
- 属性及其作用
属性 |
作用 |
border-width |
定义边框粗细,单位是px |
border-style |
定义边框样式 |
border-color |
定义边框颜色 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>边框</title>
<style>
div {
width: 400px;
height: 300px;
border-width: 5px;
/* solid 实现边框;dashed 虚线边框;dotted 点线边框 */
border-style: solid;
border-color: skyblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/df7b8b8080477dfd5c8286d06fb8f484.png)
边框的复合写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>边框复合写法</title>
<style>
div {
width: 100px;
height: 100px;
border: 2px solid skyblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/68285fd25c4d07e3b313c05f841f2127.png)
边框的分开写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>边框分开写法</title>
<style>
div {
width: 100px;
height: 100px;
/* 上边框 */
border-top: 2px solid skyblue;
/* 右边框 */
border-right: 4px dashed red;
/* 下边框 */
border-bottom: 8px dotted green;
/* 左边框 */
border-left: 16px solid skyblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/686e70ca91f67e4768394b0444430ed6.png)
边框的细线边框
- border-collapse 属性控制浏览器绘制表格边框的方式,其控制相邻单元格的边框
- 语法
boder-collapse: collapse;
- collapse 表示合并
- boder-collapse: collapse; 表示相邻边框合并在一起
- 案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表格属性</title>
</head>
<body>
<table align="center" border="1" cellpadding="2" cellspacing="0" width="500" height="250">
<tr>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
<tr>
<td>张起灵</td>