您的位置:首页 > 教程笔记 > 前端笔记

radio美化代码实例

2023-12-04 13:47:58 前端笔记 91

radio单选按钮默认状态下并不美观,但是我们可以通过其他途径将其美化。

代码实例:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="/" />
<title>实例</title>
<style>
.box{
  width:24px;
  height:18px;
  float:left;
  padding-top:3px;
  cursor:pointer;
  text-align:center;
  margin-right:10px;
  background-image:url(demo/CSS/img/inputradio.gif);
  background-repeat:no-repeat;
  background-position:-24px 0;
}
.antzone{
  opacity: 0;
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
}
.on{
  background-position: 0 0;
}
</style>
</head>
<body>
<span class="box on">
  <input type="radio" checked="checked" class="antzone">
</span>
</body>
</html>

上面的代码实现了美化效果,原理也很简单,下面做一下简单介绍。

无非就是让浏览者看到的是一个背景图片而不是真正的单选按钮(单选按钮设置为透明状态)。

相关推荐