用css写一个简单的按钮

html-css010

用css写一个简单的按钮,第1张

button{ 

    width:70px

    height:30px

    color:#fff 

    text-align: center 

    background-color:#c00 

    color:#fff

    line-height: 28px

    border-radius:15px 

    border:0 

    outline: 0 

    transition: background 0.2s 

button:hover{ 

    background:#666

} <button>Go</button>

声明楼上的答复基本上是对的

但是,还是告诉你css3可以达成“处理click事件”类似的效果,比如checkbox,click后就能利用UI元素状态伪类来实现相应的变化,这种变化有点类似处理click事件,只是小范围的应用。

比如纯css3实现的checkbox按钮开关,你可以到mxria网站上看CSS3按钮开关的实现DEMO

css3在响应用户操作上很弱,基本上还是实现静态样式为主

用CSS代码设定按钮的圆角样式,这个在css3中才能实现,通过使用border-radius来实现这个效果,不过有浏览器的兼容性问题,-moz(例如 -moz-border-radius)用于Firefox;-webkit(例如:-webkit-border-radius)用于Safari和Chrome;border-radius:5px 15px 20px 25px它的意思就是上的圆角5px,右的圆角15px,下的圆角20px,左的圆角25px,通过例子来实际看下:

<div id="round"></div>

#round {

   padding:10pxwidth:300pxheight:50px

   border: 5px solid #dedede

   -moz-border-radius: 15px     /* Gecko browsers */

   -webkit-border-radius: 15px  /* Webkit browsers */

   border-radius:15px           /* W3C syntax */

}

效果如图: