永兴集团(中国区)官方网站-Macau App Station

400-800-9385
网站建设资讯详细

网页前端制作之自定义复选框和单选框的样式

发表日期:2023-10-28 14:31:18   作者来源:林志平   浏览:2079   标签:网页前端制作    
对于复选框和单选框样式的修改,可以使用CSS和JavaScript来自定义复选框(checkbox)和单选框(radio)的样式。以下是一些示例代码,展示如何实现自定义样式:

样式1

首先设置隐藏默认的复选框和单选框:
input[type="checkbox"],
input[type="radio"] {
  display: none;
}
HTML结构:

html结构

/* 定义自定义复选框的样式 */
.custom-checkbox-label {
   display: inline-block;
   width: 20px;
   height: 20px;
   background-color: #ccc;
   border: 2px solid #333;
   cursor: pointer;
}
/* 定义选中状态下的样式 */
input[type="checkbox"]:checked + .custom-checkbox-label {
   background-color: #3498db;
   border-color: #3498db;
}
/* 定义自定义单选框的样式 */
.custom-radio-label {
   display: inline-block;
   width: 20px;
   height: 20px;
   background-color: #ccc;
   border: 2px solid #333;
   border-radius: 50%; /* 圆形单选框 */
   cursor: pointer;
}
/* 定义选中状态下的样式 */
input[type="radio"]:checked + .custom-radio-label {
   background-color: #3498db;
   border-color: #3498db;
}
自定义复选框(Checkbox)和单选框(Radio)的样式,都是创建自定义的标签元素(
如没特殊注明,文章均为永兴集团原创,转载请注明来自/news/6892.html
XML 地图