Why cannot change checkbox color whatever I do?

前端 未结 14 2211
孤城傲影
孤城傲影 2020-11-28 08:54

I try to style checkbox background color, but it won\'t change whatever I do. I am using firefox 29 latest.

Is there some rule changes in css or may be in the browse

相关标签:
14条回答
  • 2020-11-28 08:59

    you cant change the background of checkbox but some how you can do a trick try this :)

    .divBox {
        width: 20px;
        height: 20px;
        background: #ffffd;
        margin: 20px 90px;
        position: relative;
        -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
        -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
        box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
    }
    
    .divBox label {
        display: block;
        width: 20px;
        height: 20px;
        -webkit-transition: all .5s ease;
        -moz-transition: all .5s ease;
        -o-transition: all .5s ease;
        -ms-transition: all .5s ease;
        transition: all .5s ease;
        cursor: pointer;
        position: absolute;
        top: 1px;
        z-index: 1;
        /* 
        use this background transparent to check the value of checkbox 
        background: transparent;
        */
        background: Black;
        -webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
        -moz-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
        box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
    }
    
    .divBox input[type=checkbox]:checked + label {
        background: green;
    }
    <div class="divBox">
        <input type="checkbox" value="1" id="checkboxFourInput"name="" />
        <label for="checkboxFourInput"></label>
    </div>

    0 讨论(0)
  • 2020-11-28 09:06

    Styling the arrow & the checkbox colors.

    I haven't seen any answer deal with the arrow colors, so I thought I might add this for those wanting to also style the arrow inside the checkbox. I'm not suggesting to do these things, it's just for demo purposes.

    .checkbox-label {
        display: block;
        position: relative;
        margin: auto;
        cursor: pointer;
        font-size: 22px;
        line-height: 24px;
        height: 24px;
        width: 24px;
        clear: both;
    }
    
    .checkbox-label input {
        position: absolute;
        opacity: 0;
        cursor: pointer;
    }
    
    .checkbox-label .checkbox-custom {
        position: absolute;
        top: 0px;
        left: 0px;
        height: 24px;
        width: 24px;
        background-color: transparent;
        border-radius: 5px;
        transition: all 0.3s ease-out;
        -webkit-transition: all 0.3s ease-out;
        -moz-transition: all 0.3s ease-out;
        -ms-transition: all 0.3s ease-out;
        -o-transition: all 0.3s ease-out;
        border: 2px solid #000;
    }
    
    
    .checkbox-label input:checked ~ .checkbox-custom {
        background-color: #FFEA00;
        border-radius: 5px;
        -webkit-transform: rotate(0deg) scale(1);
        -ms-transform: rotate(0deg) scale(1);
        transform: rotate(0deg) scale(1);
        opacity:1;
        border: 2px solid #000;
    }
    
    .checkbox-label .checkbox-custom::after {
        position: absolute;
        content: "";
        left: 12px;
        top: 12px;
        height: 0px;
        width: 0px;
        border-radius: 5px;
        border: solid #000;
        border-width: 0 3px 3px 0;
        -webkit-transform: rotate(0deg) scale(0);
        -ms-transform: rotate(0deg) scale(0);
        transform: rotate(0deg) scale(0);
        opacity:1;
        transition: all 0.3s ease-out;
        -webkit-transition: all 0.3s ease-out;
        -moz-transition: all 0.3s ease-out;
        -ms-transition: all 0.3s ease-out;
        -o-transition: all 0.3s ease-out;
    }
    
    
    .checkbox-label input:checked ~ .checkbox-custom::after {
      -webkit-transform: rotate(45deg) scale(1);
      -ms-transform: rotate(45deg) scale(1);
      transform: rotate(45deg) scale(1);
      opacity:1;
      left: 8px;
      top: 3px;
      width: 6px;
      height: 12px;
      border: solid #000000;
      border-width: 0 2px 2px 0;
      background-color: transparent;
      border-radius: 0;
    }
    <div class="checkbox-container">
            <label class="checkbox-label">
                <input type="checkbox">
                <span class="checkbox-custom"></span>
            </label>
    </div>

    0 讨论(0)
  • 2020-11-28 09:08

    I had the same issue, trying to use large inputs and had a very small checkbox. After some searching, this is good enough for my needs:

    input[type='checkbox']{
      width: 30px !important;
      height: 30px !important;
      margin: 5px;
      -webkit-appearance: none;
      -moz-appearance: none;
      -o-appearance: none;
      appearance:none;
      outline: 2px solid lightblue;
      box-shadow: none;
      font-size: 2em;
    }
    

    JSFiddle

    Maybe someone will find it useful.

    0 讨论(0)
  • 2020-11-28 09:09

    Agree with iLoveTux , applying too many things (many colors and backgrounds) nothing worked , but here's what started working, Apply these properties to its css:

    -webkit-appearance: none;
      -moz-appearance: none;
      -o-appearance: none;
      appearance:none;
    

    and then css styling started working on checkbox :)

    0 讨论(0)
  • 2020-11-28 09:09

    I also had this problem. I use chrome to code because I'm currently a newbie. I was able to change the colour of the checkboxes and radio selectors when they were checked ONLY using CSS. The current degree that is set in the hue-rotate() turns the blue checks red. I first used the grayscale(1) with the filter: but you don't need it. However, if you just want plain flat gray, go for the grayscale value for filter.

    I've ONLY tested this in Chrome but it works with just plain old HTML and CSS, let me know in the comments section if it works in other browsers.

    input[type="checkbox"],
    input[type="radio"] {
      filter: hue-rotate(140deg);
      }
    <body>
      <label for="radio1">Eau de Toilette</label>
      <input type="radio" id="radio1" name="example1"><br>
      <label for="radio2">Eau de Parfum</label>
      <input type="radio" id="radio2" name="example1"><br>
      <label for="check1">Orange Zest</label>
      <input type="checkbox" id="check1" name="example2"><br>
      <label for="check2">Lemons</label>
      <input type="checkbox" id="check2" name="example2"><br>
     </body>

    0 讨论(0)
  • 2020-11-28 09:10

    Yes, you can. Based on knowledge from colleagues here and researching on web, here you have the best solution for styling a checkbox without any third-party plugin:

    input[type='checkbox']{
      width: 14px !important;
      height: 14px !important;
      margin: 5px;
      -webkit-appearance: none;
      -moz-appearance: none;
      -o-appearance: none;
      appearance: none;
      outline: 1px solid gray;
      box-shadow: none;
      font-size: 0.8em;
      text-align: center;
      line-height: 1em;
      background: red;
    }
    
    input[type='checkbox']:checked:after {
      content: '✔';
      color: white;
    }
    <input type='checkbox'>

    0 讨论(0)
提交回复
热议问题