style
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<style>
h1{
color: crimson;
}
</style>
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
link:css引入css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<link rel="stylesheet" href="css第一个程序/css01.css">
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
css的优势
内容和表现分离
网页结构表现统一 可以重复使用
样式丰富
容易被搜索引擎收录
div 标签
块标签
用于html的容器
和css一起使用 继续文档布局
css的n中导入方式
行内
<body>
<h1>我是标签</h1>
<!--行内样式在标签元素中编写一个 style 属性 编写样式-->
<h1 style="color: crimson">
奥特曼
</h1>
</body>
外部
链接式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<link rel="stylesheet" href="css第一个程序/css01.css">
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
导入式
css2.1
<style>@import url("文件")</style>
内部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<style>
h1{
color: crimson;
}
</style>
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
优先级
就近原则 谁离的作用代码越近
选择器
作用:选择页面上的某一个汉族某一类元素
基本选择器
标签选择器 选择一类标签 标签{}
类选择器 class 选择所有class属性一致的 .类{}
id选择器 全局唯一 .id名{}
id选择器 >类选择器> 标签选择器
标签选择器
<style>
<!--标签选择器 会选择到页面上使用的标签的元素-->
h1{
color: #a048a7;
background: #24b386;
border-radius: 23px;
}
p{
font-size: 99px;
color: green;
color: #a048a7;
background: #24b386;
border-radius: 23px;
}
</style>
类选择器class
好处可以多个标签归类是同一个class可以复用
<标签名 class=“类1 类2” ></标签名>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
<!-- 类选择器的格式.class的名称{}
好处可以多个标签归类是同一个class可以复用-->
.sy{
color: #24b386;
}
.yy{
color: #2343;
}
</style>
</head>
<body>
<h1 class="sy">淑钰</h1>
<h1 class="yy">钰钰</h1>
<h1 class="sy">钰钰很帅</h1>
<p class="yy">我是个内容</p>
</body>
</html>
id选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*
id 选择器 #id名称{}id 必须保证 全局唯一
*/ #钰钰{
color: #a048a7;
}.SS{
color: green;
}
</style>
</head>
<body>
<h1 id="钰钰">标签1</h1>
<h1 CLASS="SS">标签2</h1>
<h1 class="SS">卍卐</h1>
<h1>标签4</h1>
</body>
</html>
id选择器 >类选择器> 标签选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*
id 选择器 #id名称{}id 必须保证 全局唯一
*/ #钰钰{
color: #a048a7;
}.SS{
color: green;
}
h1{
color: aqua;
}
</style>
</head>
<body>
<h1 id="钰钰">标签1</h1>
<h1 CLASS="SS">标签2</h1>
<h1 class="SS">卍卐</h1>
<h1>标签4</h1>
</body>
</html>
并集选择器
选择器1 选择器2 选择器3{
}
全局选择器
一般用于清空边距和间距
*{
}
层次选择器
后代选择器
body p{
background: #24b386;
}
子选择器
body>p{
color: crimson;
}
相邻选择器(对下 下一个 同类型)
.a1+p{
background: #a048a7;
}
通用选择器(对下 所有同类型)
.a1~p{
background: #a048a7;
}
结构伪类选择器
伪类:条件(或者特效)
特效
a:hover{
background: crimson;
}
条件`
选择器 | 功能描述 |
---|---|
E:first-child | 作为父元素的第一个子元素的元素 E |
E:last-child | 作为父元素的最后一个子元素的元素 E |
E F:nth-child(n) | 选择父级元素 E 的第 n 个子元素 F ,( n 可以是 1 、 2 、 3 ),关键字为 even 、 odd |
E:first-of-type | 选择父元素内具有指定类型的第一个 E 元素 |
E:last-of-type | 选择父元素内具有指定类型的最后一个 E 元素 |
E F:nth-of-type(n ) | 选择父元素内具有指定类型的第 n 个 F 元素 |
<style>
/*避免使用class id*/
/*ul 第一个*/
ul li:first-of-type{
background:darkblue;
}
/*最后一个*/
ul li:last-child{
background: 2px,darkgoldenrod;
}
/*选择p1:定位父元素(body) 选择第一个元素(p)*/
p:nth-child(1){
/*选择p元素的父元素 选择第一个:并且是第一个元素才生效*/
background: #a048a7;
}
p:nth-child(2){
/*选择父元素 下p元素的第二个 类型*/
background: crimson;
}
</style>
属性选择器
相当于id+class
属性名:属性名=属性值(正则)
=为绝对等于
*=为包含这个元素
^=以这个开头
$=以这个结尾
选择器 | 类 型 | 功能描述 |
---|---|---|
E F | 后代选择器 | 选择 E 后面的所有 F 后代 |
E>F | 子选择器 | 选择 E 后面的儿子 |
E+F | 相邻兄弟选择器 | 选择 E 相邻 F 兄弟(相邻的下一个兄弟) |
E~F | 通用兄弟选择器 | 选择 E 相邻 所有 F 兄弟( 所有兄弟姐妹) |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.bar a{
}
/*属性名:属性名=属性值(正则)*/
/* =为绝对等于*/
/* *=为包含这个元素*/
/* ^=以这个开头*/
/* $=以这个结尾*/
/* 存在id的 */
a[id]{
background: #5151ad;
}
/*id为4的*/
a[id="4"]{
background: green;
}
/*capss为4的*/
a[class*="23"]{
background: crimson;
}
/*选择href 3开头的元素*/
a[href^="3"]{
background: #a048a7;
}
a[class$="x"]{
background: aqua;
}
</style>
</head>
<body>
<p class="bar">
<a href="23.com"class="d1"id="1">1</a>
<a href="34.com" class="_b1" title="ws">2</a>
<a href="2334.com"id="2">3</a>
<a href="4.com"id="4">4</a>
<a href="233.com" class="23">5</a>
<a href="2333.com" class="23">6</a>
<a href="2333.com" class="7x">6</a>
</p>
</body>
</html>
美化网页
有效的传递页面信息
美化网页 页面漂亮 才能吸引用户
凸显网页的主题
提高用户体验
span 标签
行内标签 没有特定含义 改变局部样式 设置文本样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#d1{
font-size: 20px;
dominant-baseline: alphabetic;
background: #24b386;
}
</style>
</head>
<body>
学习<span id="d1">java</span>
</body>
</html>
字体样式font
字体 font-family: 楷体;
字体大小 font-size: 50px;
字体粗 font-weight: bold; 也可以用px
字体颜色 color: #24b386;
边距 margin:0px;
字体细 font-weight: lighter;
属性名 | 含义 | 举例 |
---|---|---|
font-family | 设置字体类型 | font-family:" 隶书 "; |
font-size | 设置字体大小 | font-size:12px; |
font-style | 设置字体风格 | font- style:italic ; |
font-weight | 设置字体的粗细 | font- weight:bold ; |
font | 在一个声明中设置所有字体属性 | font:italic bold 36px " 宋体 "; |
weight 属性
值 | 说明 |
---|---|
normal | 默认值,定义标准的字体 |
bold | 粗体字体 |
bolder | 更粗的字体 |
lighter | 更细的字体 |
100 、 200 、 300 、 400 、 500 、 600 、 700 、 800 、 900 | 定义由细到粗的字体 400 等同于 normal , 700 等同于 bold |
背景background
背景颜色 background-color: #24b386;
背景图像 background-image:url(路径)
repeat 水平和垂直平铺
no-repeat 不平铺
repeat-x只水平平铺
repeat-y只垂直平铺
背景大小控制
background-size
属性值 | 描述 |
---|---|
auto | 默认值,使用背景图片保持原样 |
percentage | 当使用百分值时,不是相对于背景的尺寸大小来计算的,而是相对于元素宽度来计算的 |
cover | 整个背景图片放大填充了整个元素 |
contain | 让背景图片保持本身的宽高比例,将背景图片缩放到宽度或者高度正好适应所定义背景的区域 |
定位
background-positon属性
值 | 含义 |
---|---|
Xpos Ypos | 单位:px,Xpos表示水平位置,Ypos表示垂直位置 |
X% Y% | 使用百分比表示背景的位置 |
X、Y方向关键词 | 水平方向的关键词: *left、center、right 垂直方向的关键词: top、center、bottom ** |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*<!--
字体 font-family: 楷体;
字体大小 font-size: 50px;
字体粗 font-weight: bold; 也可以用px
字体颜色 color: #24b386;
边距 margin:0px;
字体细 font-weight: lighter;
*/ h1{
font-size: 50px;
}
body{
font-family: "BERNIER Regular",楷体;
color: #24b386;
}
.p1{
font-weight: bold;
}
.p2{
font-weight: lighter;
}
</style>
</head>
<body>
<h1>作文</h1>
<p class="p1">第一作文网提供:高中作文大全,高中作文800字范文,
</p><p class="p2">高中优秀作文800字,高中高考作文题目,高中作文素材大全等。
</p>
<p>Hello Everyone, My name is Xiao Ling from class four Grade eight, I'm 14 ye</p>
</body>
</html>
font:字体粗细 大小 行高 字体;
font: oblique 10px/12px
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
P{
/* 字体粗细 大小 行高 字体*/
font: oblique 10px/12px "楷体";
}
</style>
</head>
<body>
<p>测试</p>
</body>
</html>
vertocal-alihn属性:muddle top
文本样式text
居中 text-align: center;
右靠 text-align: right;
左靠 text-align: left;
首行缩进 text-indent: 2em;或者是px
值 | 说明 |
---|---|
left | 把文本排列到左边。默认值:由浏览器决定 |
right | 把文本排列到右边 |
center | 把文本排列到中间 |
justify | 实现两端对齐文本效果 |
阴影 text-shadow:(颜色 x y 阴影半径)
行高 line-height: 20px; 单行上下居中 line-height=height
文本装饰
text-decoration属性
值 | 说明 |
---|---|
none | 默认值,定义的标准文本 |
underline | 设置文本的下划线 |
overline | 设置文本的上划线 |
line-through | 设置文本的删除线 |
文体图片水平对齐 vertical-align:middle;
去除项目符号 list-style:none;
属性 | 含义 | 举例 |
---|---|---|
color | 设置文本颜色 | color:#00C; |
text-align | 设置元素水平对齐方式 | text- align:right ; |
text-indent | 设置首行文本的缩进 | text-indent:20px; |
line-height | 设置文本的行高 | line-height:25px; |
text-decoration | 设置文本的装饰 | text- decoration:underline ; |
列表样式*list-style
值 | 说明 | 语法示例 |
---|---|---|
none | 无标记符号 | list-style-type:none; |
disc | 实心圆,默认类型 | list-style-type:disc; |
circle | 空心圆 | list-style-type:circle; |
square | 实心正方形 | list-style-type:square; |
decimal | 数字 | list-style-type:decimal |
伪类
**a:hover {color:#FF00FF;} 鼠标悬浮颜色 **
伪类名称 | 含义 | 示例 |
---|---|---|
a:link | 未单击访问时超链接样式 | a:link{color:#9ef5f9;} |
a:visited | 单击访问后超链接样式 | a:visited {color:#333;} |
a:hover | 鼠标悬浮其上的超链接样式 | a:hover{color:#ff7300;} |
a:active | 鼠标单击未释放的超链接样式 | a:active {color:#999;} |
a:link {color:#FF0000;} /* 未访问的链接 */
a:visited {color:#00FF00;} /* 已访问的链接 */
a:hover {color:#FF00FF;} /* 鼠标划过链接 */
a:active {color:#0000FF;} /* 已选中的链接 */
/*默认*/
a{
text-decoration: aqua;
color: #5151ad;
}
/*鼠标悬浮颜色*/
a:hover{
color: #ff00f0;
font-size: 50px;
}
/*鼠标点击颜色*/
a:active{
color: green;
}
渐变linear
属 性 名 | IE | Firefox | Chrome | Opera | Safari |
---|---|---|---|---|---|
Gradient | 10+ | 19.0+ | 26.0+ | 12.1+ | 5.1+ |
linear-gradient ( position, color1, color2,…)
linear-gradient ( 方向, 颜色1, 颜色2,…)
列表
值 | 说明 | 语法示例 |
---|---|---|
none | 无标记符号 | list-style-type:none; |
disc | 实心圆,默认类型 | list-style-type:disc; |
circle | 空心圆 | list-style-type:circle; |
square | 实心正方形 | list-style-type:square; |
decimal | 数字 | list-style-type:decimal |
盒子模型
盒子模型 网页上的元素 是从上到下 从左到右排序的 每个元素都是个盒子有宽度width和高度 height
borde | 边框 |
margin | 外边框(两个元素"标签"的距离 上右下左) |
padding | 内边距(内容和边框的距离 上右下左) |
height | 高 |
width | 宽 |
外边距 居中
margin:0px auto
块元素 而且块元素有固定的宽度
img{
margin:0px auto;
}
</style>
</head>
<body>
<div >
<img src="3.jpg" alt="" style="display: block">
边框
border:5px dotted red;
边距 粗细 样式 颜色
body 总有一个默认的内外边距margin:0
- | 属性 | 说明 | 示例 |
| ----------------------: | ------------------------------------------------------------ | -------------------------------------- |
| border-top-color | 上边框颜色 | border-top-color:#369; |
| border-right-color | 右边框颜色 | border-right-color:#369; |
| border-bottom-color | 下边框颜色 | border-bottom-color:#fae45b; |
| border-left-color | 左边框颜色 | border-left-color:#efcd56; |
| border-color | 四个边框为同一颜色 | border-color:#eeff34; |
| border-color | 上、下边框颜色 : #369 左、右边框颜色 : #000 | border-color:#369 #000; |
| border-color | 上边框颜色 : #369 左、右边框颜色 : #000 下边框颜色 : #f00 | border-color:#369 #000 #f00; |
| border-color | 上、右、下、左边框颜色 : #369 、 #000 、 #f00 、 #00f | border-color:#369 #000 #f00 #00f; |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#i1{
width: 300px;
border: 5px solid red;
}
form{
background: #ff00f0;
}
body{
margin: 0px;
}
div:nth-of-type(1) input{
border: 3px solid #24b386;
/*边距样式 实线*/
}
div:nth-of-type(2) input {
border: 3px dashed #000000;
/*边距样式 虚线*/
}
h2{
font-size: 17px;
background-color: #224c22;
line-height: 30px;
margin: 0px;
color: aliceblue;
}
</style>
</head>
<body>
<div id="i1">
<h2>登录</h2>
<form action="#">
<div>
<span>姓名</span>
<input type="text">
</div>
<div>
<span>密码</span>
<input type="text">
</div>
</form>
</div>
</body>
</html>
盒子计算方式
元素多大 margin+border+padding+内容宽度
圆角边框border-radius
园
可以用于头像
利用 border-radius 属性 制作圆 形 的 两 个 要点
元素的宽度和高度必须 相同
圆角 的半径为元素宽度的一半,或者直接设置圆角半径值为 50%
div{
width: 100px;
height: 100px;
border: 4px solid red;
border-radius: 50%;
}
半圆形
利用 border-radius 属性 制作 半 圆 形 的 两 个 要点
制作上半圆或下半圆时,元素的宽度是高度的 2 倍,而且圆角半径为元素的高度 值
制作 左半圆或右半圆时,元素的高度是宽度的 2 倍, 而且圆角 半径为元素的宽度值
div{
width: 90px;
height: 45px;
border: 10px solid crimson;
border-radius:60px 60px 0px 0px;
}
扇形
利用 border-radius 属性 制作 扇形 遵循 “三同,一不同” 原则
“三同”是元素宽度、高度、圆角半径 相同
“一不同”是圆角取值位置不同
div{
width: 90px;
height: 90px;
border: 10px solid crimson;
border-radius:90px 0px 0px 0px;
}
盒子阴影
**box-shadow:**inset x-offset y-offset blur-radius color;
(inset 阴影 类型内 阴影 x-offsetX 轴位移 ,指定 阴影水平位移量
y-offset Y 轴位移,用来指定阴影垂直位移量 blur-radius 阴影模糊 半径阴影 向外模糊的模糊范围
color 阴影颜色,定义绘制阴影时所使用的颜色)
浮动
display 修改块或行元素属性
这个也是实现行内元素排列的方式但是很多情况都是用float
div{
width: 90px;
height: 90px;
border:1px solid #ff00f0;
/*inline 行内元素*/
display: inline;
/*inline-block 保持块元素的特性但是能写一行*/
}
span{
width: 90px;
height: 90px;
border:1px solid #ff00f0;
display: block;
/*block 块元素*/
float浮动元素
左float: left;
右float: right;
img{
width: 90px;
height: 90px;
display: block;
/*左float: left;*/
/*右float: right;*/
float: left;
}
clear塌陷问题
clear:right; | 右侧不允许有浮动元素 |
---|---|
clear:left; | 左侧不允许有浮动元素 |
clear:both; | 两侧不允许有浮动 |
clear:none | 可以浮动 |
1.增加父级高度
div {
border: 1px solid salmon;
height: 500px;
}
2.增加一个空的div清除浮动
<div class="a12"></div>
.a12{
clear: both;
margin: 0;
padding: 0;
}
3.在父级加一个overflow:scroll;元素
属性值 | 说明 |
---|---|
visible | 默认值。内容不会被修剪,会呈现在盒子之外 |
hidden | 内容会被修剪,并且其余内容是不可见的 |
scroll | 内容会被修剪,但是浏览器会显示滚动条以便查看其余内容 |
auto | **如果内容被修剪,则浏览器会显示滚 |
#div1 {
border: 1px solid #fa8072;
overflow:scroll;
}
4.父级添加伪类:after
div :after{
content:'';
disply:block;
clear:both;
}
1.空div 是不好的
2.设置父元素的高度 有了固定的高度就和被限制
3.overflow 简单 下拉的场景使用
4.父级添加伪类:after (推荐) 无副作用
display 位置不可控
float 位置可控 但是有塌陷问题
定位
position属性
static:默认值,没有定位
relative:相对定位
relative属性值
相对自身原来位置进行偏移
偏移设置:top(上为负 y轴)、left(左为负 x轴)、right、bottom
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-B4sWKM73-1636543635290)(C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20211103163036714.png)]
设置right为正值,元素往左移动,bottom设置正值,元素往上移动。负值则往与正值相反的方向移动
#third {
background-color:#C5DECC;
border:1px #395E4F dashed;
position:relative;
right:20px;
bottom:30px;
}
设置相对定位的盒子会相对它原来的位置,通过指定偏移,到达新的位置
设置相对定位的盒子仍在标准文档流中,它对父级盒子和相邻的盒子都没有任何影响
设置相对定位的盒子原来的位置会被保留下来
相对定位的使用场景
相对定位一般情况下很少自己单独使用,都是配合绝对定位使用,为绝对定位创造定位父级而又不设置偏移量
absolute:绝对定位
绝对定位的元素以它最近的一个“已经定位”的**“祖先元素”** 为基准进行偏移
如果没有已经定位的祖先元素,会以浏览器窗口为基准进行定位
绝对定位的使用场景
一般情况下,绝对定位用在下拉菜单、焦点图轮播、弹出数字气泡、特别花边等场景
fixed:固定定位
fixed属性值
偏移设置: left、right、top、bottom
类似绝对定位,不过区别在于定位的基准不是祖先元素,而是浏览器窗口
固定定位的使用场景
一般在网页中被用在窗口左右两边的固定广告、返回顶部图标、吸顶导航栏等
z-index属性
调整元素定位时重叠层的上下位置
z-index属性值:整数,默认值为0
设置了positon属性时,z-index属性可以设置各元素之间的重叠高低关系
z-index值大的层位于其值小的层上方
style
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<style>
h1{
color: crimson;
}
</style>
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
link:css引入css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<link rel="stylesheet" href="css第一个程序/css01.css">
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
css的优势
内容和表现分离
网页结构表现统一 可以重复使用
样式丰富
容易被搜索引擎收录
div 标签
块标签
用于html的容器
和css一起使用 继续文档布局
css的n中导入方式
行内
<body>
<h1>我是标签</h1>
<!--行内样式在标签元素中编写一个 style 属性 编写样式-->
<h1 style="color: crimson">
奥特曼
</h1>
</body>
外部
链接式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<link rel="stylesheet" href="css第一个程序/css01.css">
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
导入式
css2.1
<style>@import url("文件")</style>
内部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>233</title>
<!--写css的代码 style-->
<!--语法
选择器{
声明1:
声明1:
}
每一个语言最好于分号结尾
-->
<style>
h1{
color: crimson;
}
</style>
</head>
<body>
<h1>我是标签</h1>
</body>
</html>
优先级
就近原则 谁离的作用代码越近
选择器
作用:选择页面上的某一个汉族某一类元素
基本选择器
标签选择器 选择一类标签 标签{}
类选择器 class 选择所有class属性一致的 .类{}
id选择器 全局唯一 .id名{}
id选择器 >类选择器> 标签选择器
标签选择器
<style>
<!--标签选择器 会选择到页面上使用的标签的元素-->
h1{
color: #a048a7;
background: #24b386;
border-radius: 23px;
}
p{
font-size: 99px;
color: green;
color: #a048a7;
background: #24b386;
border-radius: 23px;
}
</style>
类选择器class
好处可以多个标签归类是同一个class可以复用
<标签名 class=“类1 类2” ></标签名>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
<!-- 类选择器的格式.class的名称{}
好处可以多个标签归类是同一个class可以复用-->
.sy{
color: #24b386;
}
.yy{
color: #2343;
}
</style>
</head>
<body>
<h1 class="sy">淑钰</h1>
<h1 class="yy">钰钰</h1>
<h1 class="sy">钰钰很帅</h1>
<p class="yy">我是个内容</p>
</body>
</html>
id选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*
id 选择器 #id名称{}id 必须保证 全局唯一
*/ #钰钰{
color: #a048a7;
}.SS{
color: green;
}
</style>
</head>
<body>
<h1 id="钰钰">标签1</h1>
<h1 CLASS="SS">标签2</h1>
<h1 class="SS">卍卐</h1>
<h1>标签4</h1>
</body>
</html>
id选择器 >类选择器> 标签选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*
id 选择器 #id名称{}id 必须保证 全局唯一
*/ #钰钰{
color: #a048a7;
}.SS{
color: green;
}
h1{
color: aqua;
}
</style>
</head>
<body>
<h1 id="钰钰">标签1</h1>
<h1 CLASS="SS">标签2</h1>
<h1 class="SS">卍卐</h1>
<h1>标签4</h1>
</body>
</html>
并集选择器
选择器1 选择器2 选择器3{
}
全局选择器
一般用于清空边距和间距
*{
}
层次选择器
后代选择器
body p{
background: #24b386;
}
子选择器
body>p{
color: crimson;
}
相邻选择器(对下 下一个 同类型)
.a1+p{
background: #a048a7;
}
通用选择器(对下 所有同类型)
.a1~p{
background: #a048a7;
}
结构伪类选择器
伪类:条件(或者特效)
特效
a:hover{
background: crimson;
}
条件`
选择器 | 功能描述 |
---|---|
E:first-child | 作为父元素的第一个子元素的元素 E |
E:last-child | 作为父元素的最后一个子元素的元素 E |
E F:nth-child(n) | 选择父级元素 E 的第 n 个子元素 F ,( n 可以是 1 、 2 、 3 ),关键字为 even 、 odd |
E:first-of-type | 选择父元素内具有指定类型的第一个 E 元素 |
E:last-of-type | 选择父元素内具有指定类型的最后一个 E 元素 |
E F:nth-of-type(n ) | 选择父元素内具有指定类型的第 n 个 F 元素 |
<style>
/*避免使用class id*/
/*ul 第一个*/
ul li:first-of-type{
background:darkblue;
}
/*最后一个*/
ul li:last-child{
background: 2px,darkgoldenrod;
}
/*选择p1:定位父元素(body) 选择第一个元素(p)*/
p:nth-child(1){
/*选择p元素的父元素 选择第一个:并且是第一个元素才生效*/
background: #a048a7;
}
p:nth-child(2){
/*选择父元素 下p元素的第二个 类型*/
background: crimson;
}
</style>
属性选择器
相当于id+class
属性名:属性名=属性值(正则)
=为绝对等于
*=为包含这个元素
^=以这个开头
$=以这个结尾
选择器 | 类 型 | 功能描述 |
---|---|---|
E F | 后代选择器 | 选择 E 后面的所有 F 后代 |
E>F | 子选择器 | 选择 E 后面的儿子 |
E+F | 相邻兄弟选择器 | 选择 E 相邻 F 兄弟(相邻的下一个兄弟) |
E~F | 通用兄弟选择器 | 选择 E 相邻 所有 F 兄弟( 所有兄弟姐妹) |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.bar a{
}
/*属性名:属性名=属性值(正则)*/
/* =为绝对等于*/
/* *=为包含这个元素*/
/* ^=以这个开头*/
/* $=以这个结尾*/
/* 存在id的 */
a[id]{
background: #5151ad;
}
/*id为4的*/
a[id="4"]{
background: green;
}
/*capss为4的*/
a[class*="23"]{
background: crimson;
}
/*选择href 3开头的元素*/
a[href^="3"]{
background: #a048a7;
}
a[class$="x"]{
background: aqua;
}
</style>
</head>
<body>
<p class="bar">
<a href="23.com"class="d1"id="1">1</a>
<a href="34.com" class="_b1" title="ws">2</a>
<a href="2334.com"id="2">3</a>
<a href="4.com"id="4">4</a>
<a href="233.com" class="23">5</a>
<a href="2333.com" class="23">6</a>
<a href="2333.com" class="7x">6</a>
</p>
</body>
</html>
美化网页
有效的传递页面信息
美化网页 页面漂亮 才能吸引用户
凸显网页的主题
提高用户体验
span 标签
行内标签 没有特定含义 改变局部样式 设置文本样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#d1{
font-size: 20px;
dominant-baseline: alphabetic;
background: #24b386;
}
</style>
</head>
<body>
学习<span id="d1">java</span>
</body>
</html>
字体样式font
字体 font-family: 楷体;
字体大小 font-size: 50px;
字体粗 font-weight: bold; 也可以用px
字体颜色 color: #24b386;
边距 margin:0px;
字体细 font-weight: lighter;
属性名 | 含义 | 举例 |
---|---|---|
font-family | 设置字体类型 | font-family:" 隶书 "; |
font-size | 设置字体大小 | font-size:12px; |
font-style | 设置字体风格 | font- style:italic ; |
font-weight | 设置字体的粗细 | font- weight:bold ; |
font | 在一个声明中设置所有字体属性 | font:italic bold 36px " 宋体 "; |
weight 属性
值 | 说明 |
---|---|
normal | 默认值,定义标准的字体 |
bold | 粗体字体 |
bolder | 更粗的字体 |
lighter | 更细的字体 |
100 、 200 、 300 、 400 、 500 、 600 、 700 、 800 、 900 | 定义由细到粗的字体 400 等同于 normal , 700 等同于 bold |
背景background
背景颜色 background-color: #24b386;
背景图像 background-image:url(路径)
repeat 水平和垂直平铺
no-repeat 不平铺
repeat-x只水平平铺
repeat-y只垂直平铺
背景大小控制
background-size
属性值 | 描述 |
---|---|
auto | 默认值,使用背景图片保持原样 |
percentage | 当使用百分值时,不是相对于背景的尺寸大小来计算的,而是相对于元素宽度来计算的 |
cover | 整个背景图片放大填充了整个元素 |
contain | 让背景图片保持本身的宽高比例,将背景图片缩放到宽度或者高度正好适应所定义背景的区域 |
定位
background-positon属性
值 | 含义 |
---|---|
Xpos Ypos | 单位:px,Xpos表示水平位置,Ypos表示垂直位置 |
X% Y% | 使用百分比表示背景的位置 |
X、Y方向关键词 | 水平方向的关键词: *left、center、right 垂直方向的关键词: top、center、bottom ** |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*<!--
字体 font-family: 楷体;
字体大小 font-size: 50px;
字体粗 font-weight: bold; 也可以用px
字体颜色 color: #24b386;
边距 margin:0px;
字体细 font-weight: lighter;
*/ h1{
font-size: 50px;
}
body{
font-family: "BERNIER Regular",楷体;
color: #24b386;
}
.p1{
font-weight: bold;
}
.p2{
font-weight: lighter;
}
</style>
</head>
<body>
<h1>作文</h1>
<p class="p1">第一作文网提供:高中作文大全,高中作文800字范文,
</p><p class="p2">高中优秀作文800字,高中高考作文题目,高中作文素材大全等。
</p>
<p>Hello Everyone, My name is Xiao Ling from class four Grade eight, I'm 14 ye</p>
</body>
</html>
font:字体粗细 大小 行高 字体;
font: oblique 10px/12px
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
P{
/* 字体粗细 大小 行高 字体*/
font: oblique 10px/12px "楷体";
}
</style>
</head>
<body>
<p>测试</p>
</body>
</html>
vertocal-alihn属性:muddle top
文本样式text
居中 text-align: center;
右靠 text-align: right;
左靠 text-align: left;
首行缩进 text-indent: 2em;或者是px
值 | 说明 |
---|---|
left | 把文本排列到左边。默认值:由浏览器决定 |
right | 把文本排列到右边 |
center | 把文本排列到中间 |
justify | 实现两端对齐文本效果 |
阴影 text-shadow:(颜色 x y 阴影半径)
行高 line-height: 20px; 单行上下居中 line-height=height
文本装饰
text-decoration属性
值 | 说明 |
---|---|
none | 默认值,定义的标准文本 |
underline | 设置文本的下划线 |
overline | 设置文本的上划线 |
line-through | 设置文本的删除线 |
文体图片水平对齐 vertical-align:middle;
去除项目符号 list-style:none;
属性 | 含义 | 举例 |
---|---|---|
color | 设置文本颜色 | color:#00C; |
text-align | 设置元素水平对齐方式 | text- align:right ; |
text-indent | 设置首行文本的缩进 | text-indent:20px; |
line-height | 设置文本的行高 | line-height:25px; |
text-decoration | 设置文本的装饰 | text- decoration:underline ; |
列表样式*list-style
值 | 说明 | 语法示例 |
---|---|---|
none | 无标记符号 | list-style-type:none; |
disc | 实心圆,默认类型 | list-style-type:disc; |
circle | 空心圆 | list-style-type:circle; |
square | 实心正方形 | list-style-type:square; |
decimal | 数字 | list-style-type:decimal |
伪类
**a:hover {color:#FF00FF;} 鼠标悬浮颜色 **
伪类名称 | 含义 | 示例 |
---|---|---|
a:link | 未单击访问时超链接样式 | a:link{color:#9ef5f9;} |
a:visited | 单击访问后超链接样式 | a:visited {color:#333;} |
a:hover | 鼠标悬浮其上的超链接样式 | a:hover{color:#ff7300;} |
a:active | 鼠标单击未释放的超链接样式 | a:active {color:#999;} |
a:link {color:#FF0000;} /* 未访问的链接 */
a:visited {color:#00FF00;} /* 已访问的链接 */
a:hover {color:#FF00FF;} /* 鼠标划过链接 */
a:active {color:#0000FF;} /* 已选中的链接 */
/*默认*/
a{
text-decoration: aqua;
color: #5151ad;
}
/*鼠标悬浮颜色*/
a:hover{
color: #ff00f0;
font-size: 50px;
}
/*鼠标点击颜色*/
a:active{
color: green;
}
渐变linear
属 性 名 | IE | Firefox | Chrome | Opera | Safari |
---|---|---|---|---|---|
Gradient | 10+ | 19.0+ | 26.0+ | 12.1+ | 5.1+ |
linear-gradient ( position, color1, color2,…)
linear-gradient ( 方向, 颜色1, 颜色2,…)
列表
值 | 说明 | 语法示例 |
---|---|---|
none | 无标记符号 | list-style-type:none; |
disc | 实心圆,默认类型 | list-style-type:disc; |
circle | 空心圆 | list-style-type:circle; |
square | 实心正方形 | list-style-type:square; |
decimal | 数字 | list-style-type:decimal |
盒子模型
盒子模型 网页上的元素 是从上到下 从左到右排序的 每个元素都是个盒子有宽度width和高度 height
borde | 边框 |
margin | 外边框(两个元素"标签"的距离 上右下左) |
padding | 内边距(内容和边框的距离 上右下左) |
height | 高 |
width | 宽 |
外边距 居中
margin:0px auto
块元素 而且块元素有固定的宽度
img{
margin:0px auto;
}
</style>
</head>
<body>
<div >
<img src="3.jpg" alt="" style="display: block">
边框
border:5px dotted red;
边距 粗细 样式 颜色
body 总有一个默认的内外边距margin:0
- | 属性 | 说明 | 示例 |
| ----------------------: | ------------------------------------------------------------ | -------------------------------------- |
| border-top-color | 上边框颜色 | border-top-color:#369; |
| border-right-color | 右边框颜色 | border-right-color:#369; |
| border-bottom-color | 下边框颜色 | border-bottom-color:#fae45b; |
| border-left-color | 左边框颜色 | border-left-color:#efcd56; |
| border-color | 四个边框为同一颜色 | border-color:#eeff34; |
| border-color | 上、下边框颜色 : #369 左、右边框颜色 : #000 | border-color:#369 #000; |
| border-color | 上边框颜色 : #369 左、右边框颜色 : #000 下边框颜色 : #f00 | border-color:#369 #000 #f00; |
| border-color | 上、右、下、左边框颜色 : #369 、 #000 、 #f00 、 #00f | border-color:#369 #000 #f00 #00f; |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#i1{
width: 300px;
border: 5px solid red;
}
form{
background: #ff00f0;
}
body{
margin: 0px;
}
div:nth-of-type(1) input{
border: 3px solid #24b386;
/*边距样式 实线*/
}
div:nth-of-type(2) input {
border: 3px dashed #000000;
/*边距样式 虚线*/
}
h2{
font-size: 17px;
background-color: #224c22;
line-height: 30px;
margin: 0px;
color: aliceblue;
}
</style>
</head>
<body>
<div id="i1">
<h2>登录</h2>
<form action="#">
<div>
<span>姓名</span>
<input type="text">
</div>
<div>
<span>密码</span>
<input type="text">
</div>
</form>
</div>
</body>
</html>
盒子计算方式
元素多大 margin+border+padding+内容宽度
圆角边框border-radius
园
可以用于头像
利用 border-radius 属性 制作圆 形 的 两 个 要点
元素的宽度和高度必须 相同
圆角 的半径为元素宽度的一半,或者直接设置圆角半径值为 50%
div{
width: 100px;
height: 100px;
border: 4px solid red;
border-radius: 50%;
}
半圆形
利用 border-radius 属性 制作 半 圆 形 的 两 个 要点
制作上半圆或下半圆时,元素的宽度是高度的 2 倍,而且圆角半径为元素的高度 值
制作 左半圆或右半圆时,元素的高度是宽度的 2 倍, 而且圆角 半径为元素的宽度值
div{
width: 90px;
height: 45px;
border: 10px solid crimson;
border-radius:60px 60px 0px 0px;
}
扇形
利用 border-radius 属性 制作 扇形 遵循 “三同,一不同” 原则
“三同”是元素宽度、高度、圆角半径 相同
“一不同”是圆角取值位置不同
div{
width: 90px;
height: 90px;
border: 10px solid crimson;
border-radius:90px 0px 0px 0px;
}
盒子阴影
**box-shadow:**inset x-offset y-offset blur-radius color;
(inset 阴影 类型内 阴影 x-offsetX 轴位移 ,指定 阴影水平位移量
y-offset Y 轴位移,用来指定阴影垂直位移量 blur-radius 阴影模糊 半径阴影 向外模糊的模糊范围
color 阴影颜色,定义绘制阴影时所使用的颜色)
浮动
display 修改块或行元素属性
这个也是实现行内元素排列的方式但是很多情况都是用float
div{
width: 90px;
height: 90px;
border:1px solid #ff00f0;
/*inline 行内元素*/
display: inline;
/*inline-block 保持块元素的特性但是能写一行*/
}
span{
width: 90px;
height: 90px;
border:1px solid #ff00f0;
display: block;
/*block 块元素*/
float浮动元素
左float: left;
右float: right;
img{
width: 90px;
height: 90px;
display: block;
/*左float: left;*/
/*右float: right;*/
float: left;
}
clear塌陷问题
clear:right; | 右侧不允许有浮动元素 |
---|---|
clear:left; | 左侧不允许有浮动元素 |
clear:both; | 两侧不允许有浮动 |
clear:none | 可以浮动 |
1.增加父级高度
div {
border: 1px solid salmon;
height: 500px;
}
2.增加一个空的div清除浮动
<div class="a12"></div>
.a12{
clear: both;
margin: 0;
padding: 0;
}
3.在父级加一个overflow:scroll;元素
属性值 | 说明 |
---|---|
visible | 默认值。内容不会被修剪,会呈现在盒子之外 |
hidden | 内容会被修剪,并且其余内容是不可见的 |
scroll | 内容会被修剪,但是浏览器会显示滚动条以便查看其余内容 |
auto | **如果内容被修剪,则浏览器会显示滚 |
#div1 {
border: 1px solid #fa8072;
overflow:scroll;
}
4.父级添加伪类:after
div :after{
content:'';
disply:block;
clear:both;
}
1.空div 是不好的
2.设置父元素的高度 有了固定的高度就和被限制
3.overflow 简单 下拉的场景使用
4.父级添加伪类:after (推荐) 无副作用
display 位置不可控
float 位置可控 但是有塌陷问题
定位
position属性
static:默认值,没有定位
relative:相对定位
relative属性值
相对自身原来位置进行偏移
偏移设置:top(上为负 y轴)、left(左为负 x轴)、right、bottom
设置right为正值,元素往左移动,bottom设置正值,元素往上移动。负值则往与正值相反的方向移动
#third {
background-color:#C5DECC;
border:1px #395E4F dashed;
position:relative;
right:20px;
bottom:30px;
}
设置相对定位的盒子会相对它原来的位置,通过指定偏移,到达新的位置
设置相对定位的盒子仍在标准文档流中,它对父级盒子和相邻的盒子都没有任何影响
设置相对定位的盒子原来的位置会被保留下来
相对定位的使用场景
相对定位一般情况下很少自己单独使用,都是配合绝对定位使用,为绝对定位创造定位父级而又不设置偏移量
absolute:绝对定位
绝对定位的元素以它最近的一个“已经定位”的**“祖先元素”** 为基准进行偏移
如果没有已经定位的祖先元素,会以浏览器窗口为基准进行定位
绝对定位的使用场景
一般情况下,绝对定位用在下拉菜单、焦点图轮播、弹出数字气泡、特别花边等场景
fixed:固定定位
fixed属性值
偏移设置: left、right、top、bottom
类似绝对定位,不过区别在于定位的基准不是祖先元素,而是浏览器窗口
固定定位的使用场景
一般在网页中被用在窗口左右两边的固定广告、返回顶部图标、吸顶导航栏等
z-index属性
调整元素定位时重叠层的上下位置
z-index属性值:整数,默认值为0
设置了positon属性时,z-index属性可以设置各元素之间的重叠高低关系
z-index值大的层位于其值小的层上方
网页元素透明度
说明 | 属性 | 举例 |
---|---|---|
x值为0~1,值越小越透明 | opacity:x | opacity:0.4; |
x值为0~100,值越小越透明 | filter:alpha(opacity=x) | filter:alpha(opacity=40); |
网页中的元素都含有两个堆叠层级
未设置绝对定位时所处的环境,z-index是0
设置绝对定位时所处的堆叠环境,此时层的位置由z-index的值确定
改变设置绝对定位和没有设置绝对定位的层的上下堆叠顺序,只需调整绝对定位层的z-index值即可
t
网页元素透明度
说明 | 属性 | 举例 |
---|---|---|
x值为0~1,值越小越透明 | opacity:x | opacity:0.4; |
x值为0~100,值越小越透明 | filter:alpha(opacity=x) | filter:alpha(opacity=40); |
网页中的元素都含有两个堆叠层级
未设置绝对定位时所处的环境,z-index是0
设置绝对定位时所处的堆叠环境,此时层的位置由z-index的值确定
改变设置绝对定位和没有设置绝对定位的层的上下堆叠顺序,只需调整绝对定位层的z-index值即可
t
子原来的位置会被保留下来
相对定位的使用场景
相对定位一般情况下很少自己单独使用,都是配合绝对定位使用,为绝对定位创造定位父级而又不设置偏移量
absolute:绝对定位
绝对定位的元素以它最近的一个“已经定位”的**“祖先元素”** 为基准进行偏移
如果没有已经定位的祖先元素,会以浏览器窗口为基准进行定位
绝对定位的使用场景
一般情况下,绝对定位用在下拉菜单、焦点图轮播、弹出数字气泡、特别花边等场景
fixed:固定定位
fixed属性值
偏移设置: left、right、top、bottom
类似绝对定位,不过区别在于定位的基准不是祖先元素,而是浏览器窗口
固定定位的使用场景
一般在网页中被用在窗口左右两边的固定广告、返回顶部图标、吸顶导航栏等
z-index属性
调整元素定位时重叠层的上下位置
z-index属性值:整数,默认值为0
设置了positon属性时,z-index属性可以设置各元素之间的重叠高低关系
z-index值大的层位于其值小的层上方
[外链图片转存中…(img-RaqAjIlu-1636543635292)]
网页元素透明度
说明 | 属性 | 举例 |
---|---|---|
x值为0~1,值越小越透明 | opacity:x | opacity:0.4; |
x值为0~100,值越小越透明 | filter:alpha(opacity=x) | filter:alpha(opacity=40); |
网页中的元素都含有两个堆叠层级
未设置绝对定位时所处的环境,z-index是0
设置绝对定位时所处的堆叠环境,此时层的位置由z-index的值确定
改变设置绝对定位和没有设置绝对定位的层的上下堆叠顺序,只需调整绝对定位层的z-index值即可
t