多语言展示
当前在线:1632今日阅读:113今日分享:31

如何做CSS3过渡效果

CSS3过渡效果有着很多的样式,我们可以通过相关的样式设定来让元素的外观与状态发生改变。当多个样式一起改变的时候,我们可以制造一个非常动感的网页效果。
工具/原料

dreamweaver

方法/步骤
1

旋转效果。当鼠标移动到这个元素的上面的时候,这个元素就会主动的进行旋转。div:hover{width:200px;height:200px;transform:rotate(180deg);-moz-transform:rotate(180deg); /* Firefox 4 */-webkit-transform:rotate(180deg); /* Safari and Chrome */-o-transform:rotate(180deg); /* Opera */}

2

过渡效果。我们设置一个两秒的时间值,从而让元素可以均匀的进行变化。div{width:100px;height:100px;background:yellow;transition:width 2s, height 2s;-moz-transition:width 2s, height 2s, -moz-transform 2s; /* Firefox 4 */-webkit-transition:width 2s, height 2s, -webkit-transform 2s; /* Safari and Chrome */-o-transition:width 2s, height 2s, -o-transform 2s; /* Opera */}

3

让元素宽度增加的效果。div{width:100px;height:100px;background:yellow;transition-property:width;transition-duration:1s;transition-timing-function:linear;transition-delay:2s;}div:hover{width:200px;}

4

设置一个从红色到黄色的动画过渡效果。@keyframes myfirst{from {background:red;}to {background:yellow;}}

5

让元素的颜色呈现多种变化。这个流程让元素有了四种变化效果。@keyframes myfirst{0%   {background:red;}25%  {background:yellow;}50%  {background:blue;}100% {background:green;}}

6

改变元素的颜色与位置。我们可以把颜色与位置的参数放在一个代码当中。@keyframes myfirst{0%   {background:red; left:0px; top:0px;}25%  {background:yellow; left:200px; top:0px;}50%  {background:blue; left:200px; top:200px;}75%  {background:green; left:0px; top:200px;}100% {background:red; left:0px; top:0px;}}

推荐信息