css3新特性小结

2020-09-27  本文已影响0人  菜菜的小阿允
一、选择器
二、边框

border-image可以使用图片来绘制边框
border-radius创建圆角边框
box-shadow可以为元素添加阴影

div{ 
    border:2px solid #e0e0e0; 
    border-radius:25px; 
    box-shadow: 10px 10px 5px #888888; 
    border-image:url(border.png) 30 30 round; 
}
三、背景

CSS3新增了几个关于背景的属性,分别是background-clip、background-origin、background-size和background-break。

background-clip

background-clip属性用于确定背景画区,有以下几种可能的属性:

通常情况,背景都是覆盖整个元素的,利用这个属性可以设定背景颜色或图片的覆盖范围。

background-origin

background-clip属性用于确定背景的位置,它通常与background-position联合使用,可以从 border、padding、content来计算background-position(就像background-clip)。

background-size

background-size属性常用来调整背景图片的大小,主要用于设定图片本身。有以下可能的属性:

background-break

CSS3中,元素可以被分成几个独立的盒子(如使内联元素span跨越多行),background-break 属性用来控制背景怎样在这些不同的盒子中显示。

div{ 
    background:url(img_flwr.gif); 
    background-repeat:no-repeat; 
    background-size:100% 100%; 
    background-origin:content-box;
} 
多背景 
body{ 
    background-image:url(img_flwr.gif),url(img_tree.gif); 
}
四、渐变

CSS3 定义了两种类型的渐变(gradients):

background: linear-gradient(direction, color-stop1, color-stop2, ...);
background: radial-gradient(center, shape size, start-color, ..., last-color);
五、文本效果
六、字体

CSS3以前的版本,网页设计师不得不使用用户计算机上已经安装的字体。使用CSS3,网页设计师可以使用他/她喜欢的任何字体。当你发现您要使用的字体文件时,只需简单的将字体文件包含在网站中,它会自动下载给需要的用户。您所选择的字体在新的CSS3版本有关于@font-face规则描述。您"自己的"的字体是在 CSS3 @font-face 规则中定义的。

<style>
    @font-face{
        font-family: myFirstFont;
        src: url(sansation_light.woff);
    }
    div{
        font-family:myFirstFont;
    }
</style>
七、CSS3 转换和变形
2D新转换属性
2D转换方法
3D转换属性
3D转换方法
八、CSS3 过渡
div{
    transition-property: width;
    transition-duration: 1s;
    transition-timing-function: linear;
    transition-delay: 2s;/* Safari */
    -webkit-transition-property:width;
    -webkit-transition-duration:1s;
    -webkit-transition-timing-function:linear;-
    webkit-transition-delay:2s;
}
九、CSS3 动画

要创建CSS3动画,你需要了解@keyframes规则。@keyframes规则是创建动画。 @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。
@keyframes 规则和所有动画属性如下:

div{
    animation-name: myfirst;
    animation-duration: 5s;
    animation-timing-function: linear;
    animation-delay: 2s;
    animation-iteration-count: infinite;
    animation-direction: alternate;
    animation-play-state: running;
    /* Safari and Chrome: */
    -webkit-animation-name: myfirst;
    -webkit-animation-duration: 5s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-delay: 2s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-direction: alternate;
    -webkit-animation-play-state: running;
}
@keyframes myfirst{
    0% {
        background: red;
    }
    25% {
        background: yellow;
    }
    50% {
        background: blue;
    }
    100% {
        background: green;
    }
}
十、CSS3 多列

CSS3 的多列属性:

十一、CSS3 用户界面

在 CSS3 中, 增加了一些新的用户界面特性来调整元素尺寸,框尺寸和外边框,主要包括以下用户界面属性:

十二、CSS3伸缩布局盒模型(弹性盒)

弹性盒子中常用到的属性:

十三、多媒体查询
使用媒体类型
<link rel="stylesheet" type="text/css" href="site.css" media="screen" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
媒体查询规则
@media all and (min-width: 800px) { ... }
// @media all 是媒体类型,也就是说,将此 CSS 应用于所有媒体类型。(min-width:800px) 是包含媒体查询的表达式,如果浏览器的最小宽度为 800 像素,则会告诉浏览器只运用下列 CSS
and 条件
@media (min-width:800px) and (max-width:1200px) and (orientation:portrait) { ... }
or 关键词
@media (min-width:800px) or (orientation:portrait) { ... }
使用 not
@media (not min-width:800px) { ... }
上一篇 下一篇

猜你喜欢

热点阅读