CSS伪类是用来添加一些选择器的特殊效果,是用于已有元素处于某种状态时为其添加对应的样式,这个状态是根据用户行为而动态变化的。
何为伪类?
就是css内置类css内部本身赋予它一些特性和功能,也就是你不用再class=...
或id=...
你就可以直接拿来使用,当然你也可以改变它的部分属性比如:a:link{color:#FF0000;}
css3新属性有哪些伪类?
-
:root 选择文档的根元素,等同于 html 元素
-
:empty 选择没有子元素的元素
-
:target 选取当前活动的目标元素
-
:not(selector) 选择除 selector 元素意外的元素
-
:enabled 选择可用的表单元素
-
:disabled 选择禁用的表单元素
-
:checked 选择被选中的表单元素
-
:after 在元素内部最前添加内容
-
:before 在元素内部最后添加内容
-
:nth-child(n) 匹配父元素下指定子元素,在所有子元素中排序第n
-
:nth-last-child(n) 匹配父元素下指定子元素,在所有子元素中排序第n,从后向前数
-
:nth-child(odd)
-
:nth-child(even)
-
:nth-child(3n+1)
-
:first-child
-
:last-child
-
:only-child
-
:nth-of-type(n) 匹配父元素下指定子元素,在同类子元素中排序第n
-
:nth-last-of-type(n) 匹配父元素下指定子元素,在同类子元素中排序第n,从后向前数
-
:nth-of-type(odd)
-
:nth-of-type(even)
-
:nth-of-type(3n+1)
-
:first-of-type
-
:last-of-type
-
:only-of-type
-
::selection 选择被用户选取的元素部分
-
:first-line 选择元素中的第一行
-
:first-letter 选择元素中的第一个字符
-
CSS3有哪些新特性
在项目开发中我们采用的CSS3新特性有
1.CSS3的选择器
1)E:last-child 匹配父元素的最后一个子元素E。
2)E:nth-child(n)匹配父元素的第n个子元素E。
3)E:nth-last-child(n) CSS3 匹配父元素的倒数第n个子元素E。2. @Font-face 特性
Font-face 可以用来加载字体样式,而且它还能够加载服务器端的字体文件,让客户端显示客户端所没有安装的字体。
-
@font-face {
-
font-family: BorderWeb;
-
src:url(BORDERW0.eot);
-
}
-
@font-face {
-
font-family: Runic;
-
src:url(RUNICMT0.eot);
-
}
-
.border { FONT-SIZE: 35px; COLOR: black; FONT-FAMILY: "BorderWeb" }
-
.event { FONT-SIZE: 110px; COLOR: black; FONT-FAMILY: "Runic" }
淘宝网字体使用
-
@font-face {
-
font-family: iconfont;
-
src: url(//at.alicdn.com/t/font_1465189805_4518812.eot);
-
}
-
3. 圆角
border-radius: 15px;
4. 多列布局 (multi-column layout)
-
-
-
新手上路
-
新手专区 消费警示 交易安全 24小时在线帮助 免费开店
-
-
付款方式
-
快捷支付 信用卡 余额宝 蚂蚁花呗 货到付款
-
-
淘宝特色
-
手机淘宝 旺信 大众评审 B格指南
-
.mul-col{
-
column-count: 3;
-
column-gap: 5px;
-
column-rule: 1px solid gray;
-
border-radius: 5px;
-
border:1px solid gray;
-
padding: 10px ;
-
}
兼容性不好,还不够成熟。还不能用在实际项目中。
5.阴影(Shadow)
-
.class1{
-
text-shadow:5px 2px 6px rgba(64, 64, 64, 0.5);
-
}
-
6.CSS3 的渐变效果
background-image:-webkit-gradient(linear,0% 0%,100% 0%,from(#2A8BBE),to(#FE280E));
这里 linear 表示线性渐变,从左到右,由蓝色(#2A8BBE)到红色(#FE280E)的渐变。效果图如下:
7.css弹性盒子模型
-
-
1
-
2
-
3
-
4
-
.boxcontainer {
-
width: 1000px;
-
display: -webkit-box;
-
display: -moz-box;
-
-webkit-box-orient: horizontal;
-
-moz-box-orient: horizontal;
-
}
-
.item {
-
background: #357c96;
-
font-weight: bold;
-
margin: 2px;
-
padding: 20px;
-
color: #fff;
-
font-family: Arial, sans-serif;
-
}
效果图
8. CSS3制作特效
-
Transition 对象变换时的过渡效果
- transition-property 对象参与过渡的属性
- transition-duration 过渡的持续时间
- transition-timing-function 过渡的类型
- transition-delay 延迟过渡的时间
缩写方式:
transition:border-color .5s ease-in .1s, background-color .5s ease-in .1s, color .5s ease-in .1s;
拆分方式:
-
transition-property:border-color, background-color, color;
-
transition-duration:.5s, .5s, .5s;
-
transition-timing-function:ease-in, ease-in, ease-in;
-
transition-delay:.1s, .1s, .1s;
示例代码
-
.main{
-
position: relative;
-
margin: 0 auto;
-
height:45px;
-
width: 300px;
-
background-color:lightgray;
-
transition:background-color .6s ease-in 0s;
-
}
-
.main:hover{
-
background-color: dimgray;
-
}
-
-