如何用css画渐变色效果圆形动画

html-css011

如何用css画渐变色效果圆形动画,第1张

要得上面的线性渐变效果,我们这样去定义CSS3样式:background-image: -moz-linear-gradient(top, #8fa1ff, #3757fa)/* Firefox */background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #ff4f02), color-stop(1,...

1、用css画一个圆形

.disc1{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin:300px 0px 0px 300px

    border-radius:100%

    float:left

}

2、由于爱心是由两个圆和一个正方形组成的,所以还需要再来一个圆形

.disc2{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin:250px 0px 0px 0px

    border-radius:100%

    float:left

    position: relative

    right: 50px

}

3、心型下方就需要做一个正方形

.square{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin: 300px 0px 0px 0px

    float: left

    position: relative

    right: 152px

}

4、做完这些的效果已经基本上出来了,但是还需要调整一下爱心的角度,这时就需要用到css样式中的transform中的rotate属性了。

由于需要把三个div都旋转角度,所以把这三个div放在一个div里面。具体代码如下:

.main{

transform: rotate(45deg)

margin: 300px

}

全部代码如下

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8" />

        <title></title>

<style type="text/css">

*{

    margin: 0px

    padding: 0px

}

.main{

    transform: rotate(45deg)

    margin: 300px

}

.disc1{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin:300px 0px 0px 300px

    border-radius:100%

    float:left

}

.disc2{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin:250px 0px 0px 0px

    border-radius:100%

    float:left

    position: relative

    right: 50px

}

.square{

    width: 100px

    height: 100px

    border:1px solid red

    background-color: red

    margin: 300px 0px 0px 0px

    float: left

    position: relative

    right: 152px

}

</style>

    </head>

    <body>

        <div class="main">

            <div class="disc1"></div>

            <div class="disc2"></div>

            <div class="square"></div>

        </div>

    </body>

</html>

1、首先新建一个html空白文档,取名字叫做css3动画,保存一下。

2、然后写html结构,只需要一个div元素即可,class名字叫做img

3、设置其边框为不同的颜色,边框宽度设置成100px。

4、因为是圆环,所以我们用到了css3的圆角效果,设置圆角为50%,也就是border-radius:50%,看一下效果。

5、接下来就是关键的步骤了,也就是添加动画效果。输入以下代码

6、来看一下最后的效果,还是不错的。