<!doctype html><!--声明文档类型为网页 H5 DTD xhtml 1.0 html 4.01-->
<html>
<head><!--设置网页基本信息,负责对外通信-->
<title><!--网页的标题--></title>
<meta charset='utf-8'><!--设置网页的编码格式,utf-8支持中文,还有gb2312 gbk国内有效-->
<meta name='keywords' content='这个是网页关键词,方便搜索引擎搜索'>
<meta name='description' content='设置网页描述信息,免费的广告位'>
<style><!--统一存放页面元素样式的区域-->
*{<!--通配符选择器,选择页面的所有标签-->
margin:0;<!--清除页面外边距-->
}
/*css复合型写法
margin:100px;四个方向
margin:20px 30px;上下 左右
margin:30px 40px 50px;上 左右 下
margin:20px 30px 40px 50px;上右下左,顺序.
css单例写法
margin-top:100px;
margin-right:200px;
margin-bottom:100px;
margin-left:100px;
相对定位居中方式,父级是body
left:50%;<!--div左端距离相对定位父级的左端50%的父级长度-->
top:50%;<!--div上端距离相对定位父级的上端50%的父级高度-->
margin-left:-50px;<!--自身宽度的一半-->
margin-top:-50px;<!---自身高度的一半-->
另一种直接居中大法
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
*/
html{
height:100%;<!--继承浏览器,或者写成inherit-->
}
body{<!---->
position:relative;<!--相对定位父级-->
height:inherit;<!--继承html-->
}
#wrap{<!--id选择器,#+id{样式}-->
left:50%;<!--div左端距离相对定位父级的左端50%的父级长度-->
top:50%;<!--div上端距离相对定位父级的上端50%的父级高度-->
position:absolute;<!--绝对定位子元素-->
width:100px;<!--属性名称:属性值(单位)-->
height:100px;
background-color:#368;
}
</style>
</head>
<!--DIV:盒子模型,在网页上划分区域的元素.CSS:修饰页面上元素的样式,宽度,高度,位置,边框,背景-->
<body><!--网页主题信息,给人看的-->
<div id='wrap'><!--id命名可以通过id找到具体的某一个标签,唯一性-->
</div>
<div class='qqq'> <!--class命名非唯一可复用,表示一组标签-->
</div>
</body>
</html>
网格布局居中
<!doctype html><!--声明文档类型为网页 H5 DTD xhtml 1.0 html 4.01-->
<html>
<head>
<title>这是一个标题</title>
<meta charset='utf-8'>
<meta name='keywords' content='这个是关键词'>
<meta name='description' content='网页描述,免费的广告位'>
<style>
*{<!--通配符选择器,选择页面的所有标签-->
margin:0;
}
html{
height:100%;
}
body{
display:grid;/*网格式布局*/
height:inherit;
}
#wrap{
margin:auto;/*自动计算页边距*/
width:100px;
height:100px;
background-color:#368;
}
#wrap .love{
width:100px;
height:150px;
background-color:red;
}
</style>
</head>
<body><!--网页主题信息,展示内容给人看的地方-->
<div id='wrap'>
<div class='love'>
</div>
</div>
</body>
</html>
伪元素
下面这种空的div标签不太规范,会让百度降低评分,不利于搜索关键词后的百度排名
任何一个元素都自带before和after,伪元素本身是一个行内元素,他无法设置行高,可以变成块级元素才可以.或者采用相对定位,相对定位的元素都会强制变成块级元素
css3圆角属性
css3的形变操作transform,例如顺时针旋转45度,逆时针就写成负的
对矩形的4个角的X轴和Y轴的圆角半径分别设置
提取公共样式,封装,防止代码重复
选择同一个class的第2个div
利用css3的transform移动,例如向上移动Y轴,向右移动X轴
CSS3执行动画
改变颜色动画
html中的css样式中声明全局变量,和使用
下面是爱心日蚀的html代码
<!doctype html><!--声明文档类型为网页 H5 DTD xhtml 1.0 html 4.01-->
<html>
<head>
<title>这是一个标题</title>
<meta charset='utf-8'>
<meta name='keywords' content='这个是关键词'>
<meta name='description' content='网页描述,免费的广告位'>
<style>
*{
margin:0;
}
html{
height:100%;
--testTime:10s;
}
body{
display:grid;
height:inherit;
background-color:skyblue;
animation:changeColor var(--testTime) linear infinite;
}
#wrap{
margin:auto;
width:100px;
height:100px;
}
#wrap .love{
position:relative;
width:200px;
height:180px;
}
#wrap .love:before
,#wrap .love:after{
position:absolute;
content:'';
width:100px;
height:150px;
background-color:yellow;
}
#wrap .love:before{
left:24px;
/*左上 右上 右下 左下,也是顺时针,这里的值代表的是圆角的半径*/
border-radius:50px 50px 0px 0px;
transform:rotate(-45deg);
}
#wrap .love:after{
left:60px;
/*左上 右上 右下 左下,也是顺时针,这里的值代表的是圆角的半径*/
border-radius:50px 50px 0px 0px;
transform:rotate(45deg);
}
#wrap .love:nth-of-type(2){
transform:translateY(-180px) translateX(200px);
/*css3执行动画 动画名称 事件 运动曲线 运动次数*/
/*css3执行动画,匀速运动animation:move 6s linear,匀速运动3次animation:move 6s linear 3,一直运动animation:move 6s linear infinite*/
animation:move var(--testTime) linear infinite;
}
#wrap .love:nth-of-type(2):before
,#wrap .love:nth-of-type(2):after{
background-color:skyblue;
animation:changeColor var(--testTime) linear infinite;
}
@keyframes move{
0%{transform:translateY(-180px) translateX(200px);}
100%{transform:translateY(-180px) translateX(-200px);}
}
@keyframes changeColor{
0%{background-color:skyblue;}
50%{background-color:black;}
100%{background-color:skyblue;}
}
</style>
</head>
<body><!--网页主题信息,展示内容给人看的地方-->
<div id='wrap'>
<div class='love'>
</div>
<div class='love'>
</div>
</div>
</body>
</html>