小白求教:css中如何将圆形渐变成心形?

html-css028

小白求教:css中如何将圆形渐变成心形?,第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>

要得上面的线性渐变效果,我们这样去定义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,...

轮廓是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用, 比如

实现线性渐变,你至少需要定义两种颜色的结点,这两种结点就是你想平稳过渡的颜色,即:其中一种颜色结点为起点,另一种颜色结点为结束点

同时也可以定义渐变的方向,是从上到下渐变,还是从左至右渐变,或者从右至左渐变,默认情况下是从上至下渐变的

当然也可以对角渐变,如:从左上角到右下角

创建重复的线性渐变

to left:设置渐变为从右到左。相当于: 270deg

to right:设置渐变从左到右。相当于: 90deg

to top:设置渐变从下到上。相当于: 0deg

to bottom:设置渐变从上到下。相当于: 180deg (这是默认值,等同于留空不写)

如果还想更多地控制渐变方向,可以改变渐变的角度

也可以在渐变中使用透明度, 所以我们得使用 rgba() 函数来定义颜色结点。 rgba() 函数中的最后一个参数可以是从 0 到 1 的值,它定义了颜色的透明度:0 表示完全透明,1 表示完全不透明

径向渐变是由中心向外渐变的。可以定义它中心 (默认渐变是中心是 center ) 、形状(圆形或椭圆形)、大小等

其中,circle 表示圆形,ellipse 表示椭圆形。默认值是 ellipse

给文字 color 添加渐变效果的话, 可以这样写: