CSS权重指的是样式的优先级,有两条或多条样式做用于一个元素,权重高的那条样式对元素起做用,权重相同的,后写的样式会覆盖前面写的样式。javascript
能够把样式的应用方式分为几个等级,按照等级来计算权重css
一、!important,加在样式属性值后,权重值为 10000
二、内联样式,如:style=””,权重值为1000
三、ID选择器,如:#content,权重值为100
四、类,伪类和属性选择器,如: content、:hover 权重值为10
五、标签选择器和伪元素选择器,如:div、p、:before 权重值为1
六、通用选择器(*)、子选择器(>)、相邻选择器(+)、同胞选择器(~)、权重值为0html
一、实例一:html5
<style type="text/css"> div{ color:red !important; } </style> ...... <div style="color:blue">这是一个div元素</div> <!-- 两条样式同时做用一个div,上面的样式权重值为10000+1,下面的行间样式的权重值为1000, 因此文字的最终颜色为red -->
二、实例二:java
<style type="text/css"> #content div.main_content h2{ color:red; } #content .main_content h2{ color:blue; } </style> ...... <div id="content"> <div class="main_content"> <h2>这是一个h2标题</h2> </div> </div> <!-- 第一条样式的权重计算: 100+1+10+1,结果为112; 第二条样式的权重计算: 100+10+1,结果为111; h2标题的最终颜色为red -->
一、E:nth-child(n):匹配元素类型为E且是父元素的第n个子元素css3
<style type="text/css"> .list div:nth-child(2){ background-color:red; } </style> ...... <div class="list"> <h2>1</h2> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <!-- 第2个子元素div匹配 -->
二、E:nth-last-child(n):匹配元素类型为E且是父元素的倒数第n个子元素(与上一项顺序相反)
三、E:first-child:匹配元素类型为E且是父元素的第一个子元素
四、E:last-child:匹配元素类型为E且是父元素的最后一个子元素
五、E:only-child:匹配元素类型为E且是父元素中惟一的子元素
六、E:nth-of-type(n):匹配父元素的第n个类型为E的子元素
七、E:nth-last-of-type(n):匹配父元素的倒数第n个类型为E的子元素(与上一项顺序相反)
八、E:first-of-type:匹配父元素的第一个类型为E的子元素
九、E:last-of-type:匹配父元素的最后一个类型为E的子元素
十、E:only-of-type:匹配父元素中惟一子元素是E的子元素
十一、E:empty 选择一个空的元素
十二、E:enabled 可用的表单控件
1三、E:disabled 失效的表单控件
1四、E:checked 选中的checkbox
1五、E:not(s) 不包含某元素web
<style type="text/css"> .list div:not(:nth-child(2)){ background-color:red; } </style> ...... <div class="list"> <h2>1</h2> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> <!-- 第 三、四、5 子元素div匹配 -->
1六、E:target 对应锚点的样式chrome
<style type="text/css"> h2:target{ color:red; } </style> ...... <a href="#tit01">标题一</a> ...... <h2 id="tit01">标题一</h2> <!-- 点击连接,h2标题变红 -->
1七、E > F E元素下面第一层子集
1八、E ~ F E元素后面的兄弟元素
1九、E + F 紧挨着的兄弟元素浏览器
属性选择器:
一、E[data-attr] 含有data-attr属性的元素ide
<style type="text/css"> div[data-attr='ok']{ color:red; } </style> ...... <div data-attr="ok">这是一个div元素</div> <!-- 点击连接,h2标题变红 -->
二、E[data-attr='ok'] 含有data-attr属性的元素且它的值为“ok”
三、E[data-attr^='ok'] 含有data-attr属性的元素且它的值的开头含有“ok”
四、E[data-attr$='ok'] 含有data-attr属性的元素且它的值的结尾含有“ok”
五、E[data-attr*='ok'] 含有data-attr属性的元素且它的值中含有“ok”
设置某一个角的圆角,好比设置左上角的圆角:
border-top-left-radius:30px 60px;
同时分别设置四个角: border-radius:30px 60px 120px 150px;
设置四个圆角相同:
border-radius:50%;
box-shadow:h-shadow v-shadow blur spread color inset;
分别设置阴影:水平偏移 垂直偏移 羽化大小 扩展大小 颜色 是否内阴影
<style type="text/css"> .box{ width:200px; height:50px; background-color:gold; /* box-shadow:10px 10px 5px 2px pink inset; */ box-shadow:10px 10px 5px 2px pink; } </style> ...... <div class="box"></div> <!-- 给盒子加上了粉红色的阴影 -->
一、盒子透明度表示法:opacity:0.1;filter:alpha(opacity=10)(兼容IE);
二、rgba(0,0,0,0.1) 前三个数值表示颜色,第四个数值表示颜色的透明度
一、transition-property 设置过渡的属性,好比:width height background-color
二、transition-duration 设置过渡的时间,好比:1s 500ms
三、transition-timing-function 设置过渡的运动方式
四、transition-delay 设置动画的延迟
五、transition: property duration timing-function delay 同时设置四个属性
<style type="text/css"> .box{ width:100px; height:100px; background-color:gold; transition:width 300ms ease,height 300ms ease 300ms,background-color 300ms ease 600ms; } .box:hover{ width:300px; height:300px; background-color:red; } </style> ...... <div class="box"></div>
一、translate(x,y) 设置盒子位移
二、scale(x,y) 设置盒子缩放
三、rotate(deg) 设置盒子旋转
四、skew(x-angle,y-angle) 设置盒子斜切
五、perspective 设置透视距离
六、transform-style flat | preserve-3d 设置盒子是否按3d空间显示
七、translateX、translateY、translateZ 设置三维移动
八、rotateX、rotateY、rotateZ 设置三维旋转
九、scaleX、scaleY、scaleZ 设置三维缩放
十、tranform-origin 设置变形的中心点
十一、backface-visibility 设置盒子背面是否可见
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>翻面</title> <style type="text/css"> .box{ width:300px; height:272px; margin:50px auto 0; transform-style:preserve-3d; position:relative; } .box .pic{ width:300px; height:272px; position:absolute; background-color:cyan; left:0; top:0; transform:perspective(800px) rotateY(0deg); backface-visibility:hidden; transition:all 500ms ease; } .box .back_info{ width:300px; height:272px; text-align:center; line-height:272px; background-color:gold; position:absolute; left:0; top:0; transform:rotateY(180deg); backface-visibility:hidden; transition:all 500ms ease; } .box:hover .pic{ transform:perspective(800px) rotateY(180deg); } .box:hover .back_info{ transform:perspective(800px) rotateY(0deg); } </style> </head> <body> <div class="box"> <div class="pic"><img src="images/location_bg.jpg"></div> <div class="back_info">背面文字说明</div> </div> </body> </html>
一、@keyframes 定义关键帧动画
二、animation-name 动画名称
三、animation-duration 动画时间
四、animation-timing-function 动画曲线
五、animation-delay 动画延迟
六、animation-iteration-count 动画播放次数 n|infinite
七、animation-direction
八、animation-play-state 动画状态
九、animation-fill-mode 动画先后的状态
十、animation:name duration timing-function delay iteration-count direction;同时设置多个属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>走路动画</title> <style type="text/css"> .box{ width:120px; height:180px; border:1px solid #ccc; margin:50px auto 0; position:relative; overflow:hidden; } .box img{ display:block; width:960px; height:182px; position: absolute; left:0; top:0; animation:walking 1.0s steps(8) infinite; } @keyframes walking{ from{ left:0px; } to{ left:-960px; } } </style> </head> <body> <div class="box"><img src="images/walking.png"></div> </body> </html>
动画中使用的图片以下:
为了让CSS3样式兼容,须要将某些样式加上浏览器前缀:
-ms- 兼容IE浏览器
-moz- 兼容firefox
-o- 兼容opera
-webkit- 兼容chrome 和 safari
好比:
div
{
-ms-transform: rotate(30deg);
-webkit-transform: rotate(30deg);
-o-transform: rotate(30deg);
-moz-transform: rotate(30deg);
transform: rotate(30deg);
}
目前的情况是,有些CSS3属性须要加前缀,有些不须要加,有些只须要加一部分,这些加前缀的工做能够交给插件来完成,好比安装: autoprefixer
Sublime text 中安装 autoprefixer 执行 preferences/key Bindings-Users 设置快捷键 { "keys": ["ctrl+alt+x"], "command": "autoprefixer" } 经过此工具能够按照最新的前缀使用状况给样式自动加前缀。
h5新增的主要语义化标签以下:
一、header 页面头部、页眉
二、nav 页面导航
三、article 一篇文章
四、section 文章中的章节
五、aside 侧边栏
六、footer 页面底部、页脚
页面使用标签布局示意图:
PC端兼容h5的新标签的方法,在页面中引入如下js文件:
<script type="text/javascript" src="//cdn.bootcss.com/html5shiv/r29/html5.js"></script>
新增类型:网址 邮箱 日期 时间 星期 数量 范围 电话 颜色 搜索
<label>网址:</label><input type="url" name="" required><br><br> <label>邮箱:</label><input type="email" name="" required><br><br> <label>日期:</label><input type="date" name=""><br><br> <label>时间:</label><input type="time" name=""><br><br> <label>星期:</label><input type="week" name=""><br><br> <label>数量:</label><input type="number" name=""> <br><br> <label>范围:</label><input type="range" name=""><br><br> <label>电话:</label><input type="tel" name=""><br><br> <label>颜色:</label><input type="color" name=""><br><br> <label>搜索:</label><input type="search" name=""><br><br>
新增经常使用表单控件属性:
一、placeholder 设置文本框默认提示文字
二、autofocus 自动得到焦点
三、autocomplete 联想关键词
html5增长了audio和video标签,提供了在页面上插入音频和视频的标准方法。
audio标签
支持格式:ogg、wav、mp3
对应属性:
一、autoplay 自动播放
二、controls 显示播放器
三、loop 循环播放
四、preload 预加载
五、muted 静音
举例:
<audio src="source/audio.mp3" autoplay controls loop preload></audio> <!-- 或者用以下方式: --> <audio autoplay controls loop preload> <source src="source/audio.mp3" type=""> <source src="source/audio02.wav" type=""> </audio>
source标签的做用是提供多个媒体文件地址,若是一个地址的文件不兼容,就使用下一个地址。
支持格式:ogg、mp四、webM
属性:
一、width
二、height
三、Poster
可选第三方播放器:
一、cyberplayer
二、tencentPlayer
三、youkuplayer
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <audio autoplay controls loop preload> <source src="myMusic.mp3" type=""> </audio> <video src="mov.mp4" controls preload="auto" width="400" height="300"> </video> </body> </html>