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

html-css09

小白求教: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>

conic-gradient是圆锥渐变,以一个点为中心起始点,沿着圆周变化。

语法: conic-gradient( from 起始角度 at 中心点位置, 渐变断点 )

兼容性:

一个简单的例子:看清他的渐变方向,起始点是图形中心,然后以顺时针方向绕中心实现渐变效果。

linear-gradient 线性渐变的方向是一条直线,可以是任何角度,向下/向上/向左/向右/对角方向。看一个简单的例子。repeating-linear-gradient()表示重复的线性渐变。

语法: background-image: linear-gradient(direction, color-stop1, color-stop2, ...)

为了创建一个线性渐变,你必须至少定义两种颜色节点。颜色节点即你想要呈现平稳过渡的颜色。同时,你也可以设置一个起点和一个方向(或一个角度)。

径向渐变是从圆心点以椭圆形状向外扩散。

语法: background-image: radial-gradient(shape size at position, start-color, ..., last-color)

shape 参数定义了形状。它可以是值 circle 或 ellipse。其中,circle 表示圆形,ellipse 表示椭圆形。默认值是 ellipse。

repeating-radial-gradient() 函数用于重复径向渐变。

https://gitee.com/susuhhhhhh/css_demos

要得上面的线性渐变效果,我们这样去定义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, #8f2c00))/* Saf4+, Chrome */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c6ff00', endColorstr='#538300', GradientType='0')/* IE*/-moz-linear-gradient有三个参数。第一个参数表示线性渐变的方向,top是从上到下、left是从左到右,如果定义成left top,那就是从左上角到右下角。第二个和第三个参数分别是起点颜色和终点颜色。你还可以在它们之间插入更多的参数,表示多种颜色的渐变。-webkit-gradient是webkit引擎对渐变的实现参数,一共有五个。第一个参数表示渐变类型(type),可以是linear(线性渐变)或者radial(径向渐变)。第二个参数和第三个参数,都是一对值,分别表示渐变起点和终点。这对值可以用坐标形式表示,也可以用关键值表示,比如 left top(左上角)和left bottom(左下角)。第四个和第五个参数,分别是两个color-stop函数。color-stop函数接受两个参数,第一个表示渐变的位置,0为起点,0.5为中点,1为结束点;第二个表示该点的颜色。IE依靠滤镜实现渐变。startColorstr表示起点的颜色,endColorstr表示终点颜色。GradientType表示渐变类型,0为缺省值,表示垂直渐变,1表示水平渐变。线性渐变使用from()以及to()方法指定过渡颜色点:background: -webkit-gradient(linear, left top, left bottom, from(#96ff00), color-stop(0.5, orange), to(rgb(255, 0, 0)))线性渐变多个过渡点在同一位置:background:-webkit-gradient(linear, left top, left bottom, from(#00abeb), to(#fff), color-stop(0.5, #fff), color-stop(0.5, #66cc00))径向渐变综合效果演示: