如何制作一个漂亮的 css 按钮

html-css010

如何制作一个漂亮的 css 按钮,第1张

启动dreamweaver,点击“站点”---“新建站点”

2

在弹出的窗口中,站点名称为“漂亮按钮”,本地站点文件夹可以根据需要选择。点击“保存”按钮,站点创建成功。

END

二、创建css文件

1

点击“文件”----“新建”,在弹出的窗体中选择“空白页”-----“CSS”,然后点击“创建”按钮。

2

点击“文件”----“保存”,在文件名中输入“style”,然后点击“保存”,样式表文件创建成功。

END

三、创建html页面

1

点击“文件”----“新建”,在弹出的窗体中选择“空白页”-----“HTML”---“无”。

2

在附加CSS文件中,选择style.css样式表文件,点击“确定”。

3

点击“创建”按钮,生成HTML文件。点击“文件”----“保存”按钮,文件名设置为“index”,最后点击保存即可。

END

三、在html页面中添加一个按钮控件

1

在“插入”-----“表单”中,点击“按钮”

2

在弹出的对话框中,什么也不需要修改,直接点击“确定”。

3

在弹出窗口中,选择“是“

4

按钮添加成功,效果如下。

END

四、新建CSS规则

1

在CSS样式表中,选择“新建CSS规则“

2

在弹出的窗口中选择”类(可应用于任何HTML元素)“,选择器名称设置为“btnstyle”,然后点击“确定”。

3

然后,在找到按钮控件,将它的类设置为”btnstyle”

END

五、用CSS规则修改按钮控件的外观

1

.btnstyle {

width: 86px/*按钮控件的宽度*/

text-align: center/*按钮控件中文本居中显示*/

line-height: 100%/*用百分比设置行高*/

padding-top: 0.5em/*文本顶部的内边距*/

padding-right: 2em/*文本右侧的内边距*/

padding-bottom: 0.55em/*文本底部的内边距*/

padding-left: 2em/*文本左侧的内边距*/

font-family: "Arial Black", Gadget, sans-serif/*字体*/

font-size: 14px/*字体大小*/

font-style: normal/*字体样式*/

font-variant: normal/*小写字母*/

font-weight: normal/*文本不需要加粗*/

text-decoration: none/*文本不需要下划线等*/

margin-top: 0px/*外边框的距离*/

margin-right: 2px/*外边框的距离*/

margin-bottom: 0px/*外边框的距离*/

margin-left: 2px/*外边框的距离*/

vertical-align: text-bottom/*图像放在文本下面*/

display: inline-block/*段落内生出内框*/

cursor: pointer/*鼠标的形状*/

zoom:1

outline-width:medium/*整个轮廓的宽度*/

outline-color:inherit/*轮廓的颜色*/

font-size-adjust:none

font-stretch:normalhttp://v.youku.com/v_show/id_XMTMzMTM0ODIzMg==.html

border-top-left-radius:0.5em/*圆角边框弧度*/

border-top-right-radius:0.5em/*圆角边框弧度*/

border-bottom-left-radius:0.5em/*圆角边框弧度*/

border-bottom-right-radius:0.5em/*圆角边框弧度*/

box-shadow:0px 1px 2px rgba(0,0,0,0.2)/*给按钮增加阴影*/

color:#fefee9/*设置文本的颜色*/

border-top-color:#da7c0c/*边框的颜色*/

border-right-color:#da7c0c/*边框的颜色*/

border-bottom-color:#da7c0c/*边框的颜色*/

border-left-color:#da7c0c/*边框的颜色*/

border-top-width:1px/*边框的粗细*/

border-right-width:1px/*边框的粗细*/

border-bottom-width:1px/*边框的粗细*/

border-left-width:1px/*边框的粗细*/

border-top-style:solid/*边框的样式*/

border-right-style:solid/*边框的样式*/

border-bottom-style:solid/*边框的样式*/

border-left-style:solid/*边框的样式*/

background-image:none/*背景图片*/

background-attachment:scroll/*背景图片是否移动*/

background-repeat:repeat/*允许重复*/

background-position-x:0%/*背景的x轴坐标*/

background-position-y:0%/*背景的y轴坐标*/

background-size:auto/*背景图片的尺寸*/

background-origin:padding-box/*背景图像相对于内边距框来定位*/

background-clip:padding-box/*背景被裁剪到内边距框*/

background-color:#f78d1d/*背景颜色*/

}更多学习5 1 r g b

2

再写一句mybtn的hover样式。代码如下:

.btnstyle:hover {

background-color: #f47c20

}

HTML结构该鼠标点击按钮特效中每一个可点击的元素都是一个按钮CSS样式以下是该css3点击按钮特效的通用CSS样式:插件中通过在点击按钮时使用javascript来为它添加相应的动画CLASS来执行动画效果:上面的CSS代码可以生成如下图的动画效果:在“Stana”效果中,使用了html5SVGclipPath,在它上面添加了一个transition。这个效果只能在Chrome浏览器中才能看到效果。在“Stoja”效果中使用了CSSclip-path属性,这个效果也需要浏览器的支持才能看得到的。

修改相关的参数,可以达到爆炸效果

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>twitterLove</title>

</head>

<body>

<canvas width="100" height="100" style="border: 1px black solid">

    必须要把style写在内联,不然会变成椭圆。而且width与height要单独写出来

    注意:1,每画一个图形都要提起笔。不然会连在一起

    2,arc的(centerX[圆心横坐标,以父节点的右上角为坐标原点,向左向下建立坐标轴],centerY,r[半径],

    startAngle[起始点的角度。起始以(1,0)表示0,(0,1)表示3/2*PI计算。当设置为逆时针的时候画出来是起点到终点之间的扇形出去中心三角],

    endAngle,anticlockwise(是否逆时针))

    3,画图的时候要计算好坐标

    4,最好以角度值百分比计算。流式布局更能适应各种大小的缩放

    5,注意提取公共函数

    6,要划分步骤

    7,注意上一幅图与下一幅图的关系。用clearRect来清除

</canvas>

<script>

    var canvas=(document.getElementsByTagName("canvas"))[0]//获取绘图区域,是一个正方形区域

    var ctx=canvas.getContext("2d")//获取画笔

    //必须写在外面,公共的

    var centerX=(canvas.width)*0.5

    var centerY=(canvas.height)*0.5//获取中心,是一个正方形

    //获得一个爱心

    function love(color,centerX,centerY,size){

        ctx.beginPath()

        //上半部

        var smallRadius=Math.round(centerX/size)//小圆的半径

        var smallMoveLen=smallRadius*Math.sqrt(3)/2

        ctx.fillStyle=color||"red"

        ctx.arc(centerX-smallMoveLen,centerY,smallRadius,Math.PI*7/4,Math.PI,true)

        ctx.arc(centerX+smallMoveLen,centerY,smallRadius,0,Math.PI*5/4,true)

        //下半部

        var bigRadius=smallRadius*2.73

        ctx.arc(centerX+smallMoveLen,centerY,bigRadius,Math.PI,Math.PI*0.6,true)

        ctx.arc(centerX-smallMoveLen,centerY,bigRadius,Math.PI*0.4,0,true)

        ctx.fill()

        ctx.closePath()

    }

    love("grey",centerX,centerY,8)//默认灰色

    //注册监听

    canvas.addEventListener("click",function () {

        if(ctx.fillStyle=="#808080"){//表示为灰色

           // alert("点赞")

            //1,爱心消失//清除画板内容

            ctx.clearRect(0,0,centerX*2,centerY*2)

            //动态图

            var bigRadius=centerX/2

            var midRadius=centerX/5

            var smallRadius=centerX/10

            //2,小圆,圆心都是中心位置

            setTimeout(function () {

                ctx.beginPath()

                ctx.fillStyle="#FF6BDB"

                ctx.arc(centerX,centerY,smallRadius,0,2*Math.PI,false)

                ctx.fill()

                ctx.closePath()//必须要提笔。不然和前面一只笔相当于没提起来

            },100)

            //3,中圆

            setTimeout(function () {

                ctx.beginPath()

                ctx.fillStyle="#9FD5FF"

                ctx.arc(centerX,centerY,midRadius,0,2*Math.PI,false)

                ctx.fill()

                ctx.closePath()

            },200)

            //4,大圆

            setTimeout(function () {

                ctx.beginPath()

                ctx.fillStyle="#FF84A6"

                ctx.arc(centerX,centerY,bigRadius,0,2*Math.PI,false)

                ctx.fill()

                ctx.closePath()

            },300)

            //5,小爱心

            setTimeout(function () {

                ctx.clearRect(0,0,centerX*2,centerY*2)

                ctx.beginPath()

                ctx.fillStyle="#FF84A6"

                ctx.arc(centerX,centerY,bigRadius,0,2*Math.PI,false)

                ctx.fill()

                ctx.closePath()

                ctx.beginPath()

                ctx.fillStyle="#ffffff"

                ctx.arc(centerX,centerY,midRadius*2,0,2*Math.PI,false)

                ctx.fill()

                ctx.closePath()

                ctx.beginPath()

                love("purple",centerX,centerY,16)

                ctx.closePath()

            },400)

            //6,四周小圆

            setTimeout(function () {

                ctx.clearRect(0,0,centerX*2,centerY*2)

                var e=bigRadius/(Math.sqrt(2))

                var centerXArr=[centerX-bigRadius,centerX-e,centerX,centerX+e,centerX+bigRadius,centerX+e,centerX,centerX-e]

                var centerYArr=[centerY,centerY-e,centerY-bigRadius,centerY-e,centerY,centerY+e,centerY+bigRadius,centerY+e]

                for(var i=0i<8i++){

                    ctx.beginPath()

                    ctx.fillStyle="blue"

                    ctx.arc(centerXArr[i],centerYArr[i],smallRadius/4,0,2*Math.PI,false)

                    ctx.fill()

                    ctx.closePath()

                }

                ctx.fillStyle="#ff0000"

                love("ff0000",centerX,centerY,8)//red

            },500)

            //7,红色大爱心

            setTimeout(function () {

                ctx.clearRect(0,0,centerX*2,centerY*2)

                ctx.beginPath()

                love("ff0000",centerX,centerY,8)

                ctx.closePath()

            },600)

        }

        else if(ctx.fillStyle=="#ff0000"){//表示为红色

           // alert("取消赞")

            ctx.fillStyle="#ff0000"

            love("#808080",centerX,centerY,8)

        }

    },false)

</script>

</body>

</html>