Giter Site home page Giter Site logo

html-css-custom-checkbox-demo's Introduction

Html Css Custom Checkbox Demo

Checkbox的styling不太容易,有几个地方需要注意:

  1. 默认的复选框的样式是由浏览器提供的,基本上不能为它设置样式。 比如框的大小没法用px指定,使用transform: scale(2)或者zoom: 2来放大,要么效果不好有毛边,要么有的浏览器不支持。

  2. 如果想对复选框进行设置,需要先隐藏浏览器自带的效果,使用appearance:none

    • 但是appearance现在浏览器不认,必须在前面加前缀,比如-webkit-appearance/-moz-appearance
    • appearance:none之后,就可以使用通常的style来修饰,比如width/height/border等
  3. 需要自定义的勾选效果,可以使用background-image

  4. label与input结合之后,会遇到复选框与文字对齐的问题(文字通常会偏下),这时需要比较复杂的方式(比如position/display/vertical-align/padding等结合)才能调整好。

  5. 对checkbox使用all: initial来重置其样式后,会发现复选框不显示,原因是appearance被重置后,会丢失原始的checkbox样式。所以需要手动指定:

    input[type=checkbox] {
      all: initial;
      -webkit-appearance: checkbox;
      -moz-appearance: checkbox;
      appearance: checkbox;
    }
    
open index.html

html-css-custom-checkbox-demo's People

Contributors

freewind avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.