checkbox styled as button input:checked background color does not occupy button space












0















I have been looking for ways to turn checkboxes to look like button, I stumbled upon this question and I did but I added a padding on mine,



.ck-button {
padding: 5px 5px 0px 5px;
}


here is the jsfiddle



As you can see, when clicked, it will just change the color of the span and not the whole button. I tried to add the padding here



.ck-button input:checked + span {
background-color:#0077CC;
color:#fff;
}


or remove the span but neither of them is working. Please help me and thank you in advance.










share|improve this question



























    0















    I have been looking for ways to turn checkboxes to look like button, I stumbled upon this question and I did but I added a padding on mine,



    .ck-button {
    padding: 5px 5px 0px 5px;
    }


    here is the jsfiddle



    As you can see, when clicked, it will just change the color of the span and not the whole button. I tried to add the padding here



    .ck-button input:checked + span {
    background-color:#0077CC;
    color:#fff;
    }


    or remove the span but neither of them is working. Please help me and thank you in advance.










    share|improve this question

























      0












      0








      0








      I have been looking for ways to turn checkboxes to look like button, I stumbled upon this question and I did but I added a padding on mine,



      .ck-button {
      padding: 5px 5px 0px 5px;
      }


      here is the jsfiddle



      As you can see, when clicked, it will just change the color of the span and not the whole button. I tried to add the padding here



      .ck-button input:checked + span {
      background-color:#0077CC;
      color:#fff;
      }


      or remove the span but neither of them is working. Please help me and thank you in advance.










      share|improve this question














      I have been looking for ways to turn checkboxes to look like button, I stumbled upon this question and I did but I added a padding on mine,



      .ck-button {
      padding: 5px 5px 0px 5px;
      }


      here is the jsfiddle



      As you can see, when clicked, it will just change the color of the span and not the whole button. I tried to add the padding here



      .ck-button input:checked + span {
      background-color:#0077CC;
      color:#fff;
      }


      or remove the span but neither of them is working. Please help me and thank you in advance.







      html css






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 3:59









      eibersjieibersji

      461521




      461521
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Try this. You have to give padding to the ck-button label span not in ck-button class.






          div label input {
          margin-right:100px;
          }
          body {
          font-family:sans-serif;
          }

          .ck-button {
          margin:4px;
          background-color:#EFEFEF;
          border-radius:4px;
          border:1px solid #D0D0D0;
          overflow:auto;
          float:left;
          /*padding: 5px 5px 5px 5px;*/
          }

          .ck-button label {
          display:block;
          width:5.0em;
          }

          .ck-button label span {
          text-align:center;
          padding:5px 5px;
          display:block;
          }

          .ck-button label input {
          position:absolute;
          opacity:0;
          /*top:-20px; don't use this thing use opacity:0 */
          }

          .ck-button input:checked + span {
          background-color:#911;
          color:#fff;
          }

          <div class="ck-button">
          <label>
          <input type="checkbox" value="1"><span>red</span>
          </label>
          </div>
          <div class="ck-button">
          <label>
          <input type="checkbox" value="2"><span>red</span>
          </label>
          </div>








          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455043%2fcheckbox-styled-as-button-inputchecked-background-color-does-not-occupy-button%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Try this. You have to give padding to the ck-button label span not in ck-button class.






            div label input {
            margin-right:100px;
            }
            body {
            font-family:sans-serif;
            }

            .ck-button {
            margin:4px;
            background-color:#EFEFEF;
            border-radius:4px;
            border:1px solid #D0D0D0;
            overflow:auto;
            float:left;
            /*padding: 5px 5px 5px 5px;*/
            }

            .ck-button label {
            display:block;
            width:5.0em;
            }

            .ck-button label span {
            text-align:center;
            padding:5px 5px;
            display:block;
            }

            .ck-button label input {
            position:absolute;
            opacity:0;
            /*top:-20px; don't use this thing use opacity:0 */
            }

            .ck-button input:checked + span {
            background-color:#911;
            color:#fff;
            }

            <div class="ck-button">
            <label>
            <input type="checkbox" value="1"><span>red</span>
            </label>
            </div>
            <div class="ck-button">
            <label>
            <input type="checkbox" value="2"><span>red</span>
            </label>
            </div>








            share|improve this answer




























              2














              Try this. You have to give padding to the ck-button label span not in ck-button class.






              div label input {
              margin-right:100px;
              }
              body {
              font-family:sans-serif;
              }

              .ck-button {
              margin:4px;
              background-color:#EFEFEF;
              border-radius:4px;
              border:1px solid #D0D0D0;
              overflow:auto;
              float:left;
              /*padding: 5px 5px 5px 5px;*/
              }

              .ck-button label {
              display:block;
              width:5.0em;
              }

              .ck-button label span {
              text-align:center;
              padding:5px 5px;
              display:block;
              }

              .ck-button label input {
              position:absolute;
              opacity:0;
              /*top:-20px; don't use this thing use opacity:0 */
              }

              .ck-button input:checked + span {
              background-color:#911;
              color:#fff;
              }

              <div class="ck-button">
              <label>
              <input type="checkbox" value="1"><span>red</span>
              </label>
              </div>
              <div class="ck-button">
              <label>
              <input type="checkbox" value="2"><span>red</span>
              </label>
              </div>








              share|improve this answer


























                2












                2








                2







                Try this. You have to give padding to the ck-button label span not in ck-button class.






                div label input {
                margin-right:100px;
                }
                body {
                font-family:sans-serif;
                }

                .ck-button {
                margin:4px;
                background-color:#EFEFEF;
                border-radius:4px;
                border:1px solid #D0D0D0;
                overflow:auto;
                float:left;
                /*padding: 5px 5px 5px 5px;*/
                }

                .ck-button label {
                display:block;
                width:5.0em;
                }

                .ck-button label span {
                text-align:center;
                padding:5px 5px;
                display:block;
                }

                .ck-button label input {
                position:absolute;
                opacity:0;
                /*top:-20px; don't use this thing use opacity:0 */
                }

                .ck-button input:checked + span {
                background-color:#911;
                color:#fff;
                }

                <div class="ck-button">
                <label>
                <input type="checkbox" value="1"><span>red</span>
                </label>
                </div>
                <div class="ck-button">
                <label>
                <input type="checkbox" value="2"><span>red</span>
                </label>
                </div>








                share|improve this answer













                Try this. You have to give padding to the ck-button label span not in ck-button class.






                div label input {
                margin-right:100px;
                }
                body {
                font-family:sans-serif;
                }

                .ck-button {
                margin:4px;
                background-color:#EFEFEF;
                border-radius:4px;
                border:1px solid #D0D0D0;
                overflow:auto;
                float:left;
                /*padding: 5px 5px 5px 5px;*/
                }

                .ck-button label {
                display:block;
                width:5.0em;
                }

                .ck-button label span {
                text-align:center;
                padding:5px 5px;
                display:block;
                }

                .ck-button label input {
                position:absolute;
                opacity:0;
                /*top:-20px; don't use this thing use opacity:0 */
                }

                .ck-button input:checked + span {
                background-color:#911;
                color:#fff;
                }

                <div class="ck-button">
                <label>
                <input type="checkbox" value="1"><span>red</span>
                </label>
                </div>
                <div class="ck-button">
                <label>
                <input type="checkbox" value="2"><span>red</span>
                </label>
                </div>








                div label input {
                margin-right:100px;
                }
                body {
                font-family:sans-serif;
                }

                .ck-button {
                margin:4px;
                background-color:#EFEFEF;
                border-radius:4px;
                border:1px solid #D0D0D0;
                overflow:auto;
                float:left;
                /*padding: 5px 5px 5px 5px;*/
                }

                .ck-button label {
                display:block;
                width:5.0em;
                }

                .ck-button label span {
                text-align:center;
                padding:5px 5px;
                display:block;
                }

                .ck-button label input {
                position:absolute;
                opacity:0;
                /*top:-20px; don't use this thing use opacity:0 */
                }

                .ck-button input:checked + span {
                background-color:#911;
                color:#fff;
                }

                <div class="ck-button">
                <label>
                <input type="checkbox" value="1"><span>red</span>
                </label>
                </div>
                <div class="ck-button">
                <label>
                <input type="checkbox" value="2"><span>red</span>
                </label>
                </div>





                div label input {
                margin-right:100px;
                }
                body {
                font-family:sans-serif;
                }

                .ck-button {
                margin:4px;
                background-color:#EFEFEF;
                border-radius:4px;
                border:1px solid #D0D0D0;
                overflow:auto;
                float:left;
                /*padding: 5px 5px 5px 5px;*/
                }

                .ck-button label {
                display:block;
                width:5.0em;
                }

                .ck-button label span {
                text-align:center;
                padding:5px 5px;
                display:block;
                }

                .ck-button label input {
                position:absolute;
                opacity:0;
                /*top:-20px; don't use this thing use opacity:0 */
                }

                .ck-button input:checked + span {
                background-color:#911;
                color:#fff;
                }

                <div class="ck-button">
                <label>
                <input type="checkbox" value="1"><span>red</span>
                </label>
                </div>
                <div class="ck-button">
                <label>
                <input type="checkbox" value="2"><span>red</span>
                </label>
                </div>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 4:12









                ankita patelankita patel

                3,5701626




                3,5701626
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455043%2fcheckbox-styled-as-button-inputchecked-background-color-does-not-occupy-button%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen