CSS自定义复选框按钮样式-绿色复选框_html/css_WEB-ITnose
HTML自带的复选框或者单选框按钮样式都是比较简单的一种. 而有时候这些表单控制, 可能需要配合自己的主题样式. 需要去美化他们. 以前可能需要借助JS的实现. 现在CSS也可以完全实现我们想要的效果.
我们直奔主题. 首先想到的是, 复选框需要的是一个背景色, 然后就是一个复选框选中的状态.选中状态我们这里用 "勾号" 来表示. HTML就可以简单的表示了
<div class="i-check"> <input type="checkbox" value="0" /> <label></label></div>
.i-check 作为整体的复选框.加入的CSS代码也简单
.i-check { width: 20px; height: 20px; position: relative; margin: 20px auto;}
复选框的大小根据自己的需要而定. 这里设置margin, 是为了显示在浏览器的中间.
然后就是设定复选框的默认状态, 这里利用label来设置, 其高度和宽度都与.i-check设置一样, 然后给其一个背景色,设置好他的位置.
.i-check label { width: 20px; height: 20px; cursor: pointer; position: absolute; top: 0; left: 0; background: #1A9909; border-radius: 4px;}
默认状态我们已经弄好了. 我们继续分析, 那这时候需要的是一个选中状态, 选中状态刚已经讲过用一个勾号表示, 这里我们利用伪类after来设置,设置其边框,及旋转这个after, 就变成了勾号.但是默认状态勾号是隐藏的, 所以我们用了opacity为0.
.i-check label:after { content: ''; width: 9px; height: 5px; position: absolute; top: 4px; left: 4px; border: 3px solid #fff; border-top: none; border-right: none; background: transparent; opacity: 0; transform: rotate(-45deg);}
好了, 整个状态设置好了. 现在需要在点击复选框的时候让勾号显示出来.下面的代码就可以完成
.i-check input[type=checkbox]:checked + label:after { opacity: 1;}
写到这里,不要忘记了, 让Input复选框设置其样式, 为了让用户能够点击到, 他的高宽度都要和整体一样大小, 让其在整个盒子的最顶层.这样用户就可以能够随便在这个区域就能点击. OK , 最后一步就是让这个input复选框隐藏起来, 隐藏起来, 不是让他真正的隐藏去掉, 这样的话, 就没有点击效果. 这里隐藏需要的是用opacity来设置为0.
.i-check input[type=checkbox] { opacity: 0; position: absolute; z-index: 2; left: 0; top: 0; width: 100%; height: 100%; margin: 0;}
好了, 整个效果就完成了, 同理这个也可以去设定单选框的效果.
本文属于吴统威的博客, 微信公众号:bianchengderen,QQ群:186659233 的原创文章,转载时请注明出处及相应链接:http://www.wutongwei.com/front/infor_showone.tweb?id=218 ,欢迎大家传播与分享.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.
