文章目录
-
- 块级元素
- 行内元素
- 行内块元素
- 背景图片,平铺,位置
- 盒子模型
- 精灵图小案例
- 总结
1.块级元素
2.行内元素
代码运行结果呈一行出现。
3.行内块元素
<!--img行内块元素 inlineblock-->
<!-- 1.不会独占一整行 -->
<!-- 2.可以设置宽度高度 -->
<!-- 3.里边可以容纳任意的元素和内容 -->
4.背景图片,平铺,位置
<!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>Document</title>
<style>
.box {
width: 150px;
height: 150px;
background-color: rgba(10, 189, 19, 0.5);
/* bgc */
}
#odiv {
width: 350px;
height: 350px;
background-image: url(../image/1.jpg);
/* image怎么写,这里就怎么写 */
/* 盒子不够大图片显示不完,盒子太大重复显示 */
/* 1.平铺 2.硬拉 */
background-repeat: no-repeat;
/* 不平铺 */
/* 背景图片是否平铺:1.no-repeat 2.repeat:repeat-x横着平铺,repeat-y竖着平铺*/
background-position: 150px 150px;
/* 改变背景位置,背景图片的定位方式 */
/* 背景算盒子本身一部分 */
}
</style>
</head>
<body>
<div class="box"></div>
<!-- div.box -->
<div class="9"></div>
<!-- div.9 -->
<div id="odiv"></div>
<!-- div# -->
<div class="jl"></div>
</body>
</html>
5.盒子模型
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
width: 150px;
height: 150px;
/* border: 5px solid blueviolet; */
/* 边框 线的粗细程度 边框的样式 颜色 */
border-top: 15px solid red;
border-right: 15px dashed blue;
border-bottom: 15px dotted pink;
border-left: 15px double green;
/* 三角形 width,height都为0,其他三边全透明,只留一边 */
}
/* 圆 */
.circle {
width: 150px;
height: 150px;
border: 1px solid red;
border-radius: 50%;
/* 可以设置四个值 变为椭圆,对角100,还有一对为0 */
background-image: url(./index.webp);
}
</style>
</head>
<body>
<div class="box"></div>
<div class="circle"></div>
</body>
</html>