Alter the color of the checkbox once it has been activated

I have a checkbox that I want to change the color of the checkmark to green when it is checked. How can I achieve this?

<input type="checkbox" checked="checked" disabled="disabled"  />

The current method I tried is not working.

<style type="text/css">
    input[type=checkbox], input[type=file] {
        display: inline-block;
        margin-right: 15px;
    }
    input[type="checkbox"]:disabled:checked + label::after {
        border: 3px solid #228B22;
        border-top: none;
        border-right: none;
    }


    input[type="checkbox"]:checked + label::after {
        content: '';
        position: absolute;
        width: 1.2ex;
        height: 0.4ex;
        background: rgba(0, 0, 0, 0);
        top: 0.9ex;
        left: 0.4ex;
        border: 3px solid #1062a4;
        border-top: none;
        border-right: none;
        -webkit-transform: rotate(-45deg);
        -moz-transform: rotate(-45deg);
        -o-transform: rotate(-45deg);
        -ms-transform: rotate(-45deg);
        transform: rotate(-45deg);
    }
</style>

Answer №1

UPDATE *

I have made some adjustments to the FIDDLE to include both enable (green) and disable styles:

input[type="checkbox"]:disabled:checked + label::after {
    border: 3px solid #228B22;
    border-top: none;
    border-right: none;
}


input[type="checkbox"]:checked + label::after {
   content: '';
   position: absolute;
   width: 1.2ex;
   height: 0.4ex;
   background: rgba(0, 0, 0, 0);
   top: 0.9ex;
   left: 0.4ex;
   border: 3px solid #1062a4;
   border-top: none;
   border-right: none;
   -webkit-transform: rotate(-45deg);
   -moz-transform: rotate(-45deg);
   -o-transform: rotate(-45deg);
   -ms-transform: rotate(-45deg);
   transform: rotate(-45deg);
}

FIDDLE

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The use of pattern fill in fabric.js is causing a decrease in rendering speed

I recently attempted to create a clip mask effect on a large image by using the picture as a pattern and setting it to the svg paths that support the desired shape. You can view the slow-loading jsfiddle example here: http://jsfiddle.net/minzojian/xwurbw ...

The fixed table header is misaligned with the body columns' width

I was looking for a way to add a vertical scrollbar to my table, and I ended up wrapping the entire table in a div. The result was that the table head was fixed in position. Is there a simpler method to include a scrollbar in a table without affecting the ...

While it includes a new section, it fails to refresh the navbar

Upon clicking the button to add a new section, the section gets added successfully. However, the navbar does not get updated as expected. It should dynamically update the navbar to display both the existing sections and the new section added using JavaScri ...

Struggling to position elements at the edges in Bootstrap

My goal is to move the elements to the corners of the screen. Despite trying the code below, it doesn't seem to be working as expected. <!-- Page Footer --> <footer> <div class="navbar mt-3 py-3 bg-dark"> <div class=&q ...

In Chrome, the `Jquery $('input[name=""]').change(function will not be triggered unless there is an unhandled error following it

Here is a script that I've created to make certain inputs dependent on the selection of a radio button. The 'parent' input in this case is determined by the radio button choice. Upon document load, the script initially hides parent divs of ...

Selenium Assistance: I'm encountering a scenario where on a webpage, two elements share the same Xpath, making it difficult to differentiate them based on even

At index [1], both elements are identified, but at index [2], nothing is identified. The key difference between the two is that one has display:none, and the other has display:block. However, their involvement in determining these fields is minimal due to ...

What is the best way to display Bootstrap dynamic tabs in a single row without them overflowing and requiring a scroll button to access all the tabs

Is there a way to dynamically display Bootstrap tabs? I want the content in the tab to show when the link is clicked, and also have a close button. I need the tabs to be aligned in a single row without wrapping down if they don't fit. Here's an ...

Using gridviews with various data sources in Visual Basic .NET

Can columns of a gridview be bound to different data sources? I have two distinct datasources specified in my web.config file and I am looking to display data from them in a single gridview. What is the best approach to populate a dataset or datatable for ...

jquery mobile's grid system allows for easy creation of responsive layouts

Looking to create a responsive page with Jquery Mobile. Currently using ui-grid for a 3 column layout on wide screens and media queries for a 3 row, 1 column grid on mobile. However, my goal is to display only the first grid on mobile, with subsequent gri ...

Unable to click on overlay in Internet Explorer version 8

When I click my overlay in different browsers like Firefox, Chrome, and IE9, the onClick function is triggered as expected. However, in IE8, it seems like the box is not clickable at all and the content behind it is receiving the click events instead. Here ...

Unable to apply filter in IE11

When applying color to bootstrap 2.3.2 Icons, I utilize the filter property in CSS. While this method is effective in most browsers, it does not work as expected in IE11. .apply-color { filter: opacity(0.5) drop-shadow(0 0 0 blue); } What is the worka ...

Identifying whether a class exists on the same level using a selector

Snippet display: $( document ).ready(function() { //$(".tree-node").parents('.tree-child-folders').css("color", "red"); //$(".tree-collapsed:has(.tree-child-folders)").css("color", "red"); $(".tree-node > .tree-collapsed:has(.tree-child ...

Tips for transforming HTML to a dynatable or datatable

I have a PHP page that returns HTML table data. I’m looking to convert this table into either DataTable or Dynatable. I’ve attempted to include the necessary files (JavaScript and CSS) in the page where the PHP script generates the table. In my JavaScr ...

Stable element contained within a moving container

My content block has text that scrolls when it becomes too large. I'm trying to create an overlay div on top of this block, and I have implemented a solution in my example. I encountered issues where setting position: fixed for the overlay prevents i ...

Explore the world of online shopping with ASP.NET MVC and jQuery shopping cart integration

In my pricing page, I have a list of products with their prices that users can add to the shopping cart. The active shopping cart is displayed on the right-hand side of the page. Currently, I am using Ajax/Jquery to implement this feature... Within my ASP ...

How can I utilize jQuery to add tags in a box?

I have an idea for a feature similar to the Stack Overflow tag insert. My goal is to have a box where I can type in a tag, click 'Add', and see it appear above. Additionally, I want this action to update an array called 'SelectedTags'. ...

Enhancing Performance of AJAX AutoComplete feature in ASP.NET using C#

One issue is that the list of suggestions appears far below the actual text box. Refer to the image for clarification. The second problem is that there is a delay of one to two seconds before any results are displayed using auto completion. This delay doe ...

I am facing an issue where cookies are not being saved in the browser when calling from the client side using Axios. However, it works perfectly fine when calling from the server side. I am unsure of

Clarification of the issue When I run it from the server side, i.e., http://localhost:3001, the cookie is saved in my browser without any issues. However, when I call it from the client side using const result = await Axios({ method: "post", url: "http:// ...

What is the reason behind Internet Explorer 11 not supporting conditional comments in HTML? Has this feature been dropped?

I'm having an issue trying to show different content on various web browsers. When using Internet Explorer 11 and Google Chrome 39, the message displayed is "Not Internet Explorer" instead of the expected result. Is there a problem with my code? It&ap ...

Problem with Silverstripe: Replicating Site configuration or settings menu

I have duplicated the Settings menu (siteConfig) folder in order to create a new CMS menu for inputting company information. The functionality of the menu is working correctly, however, the CSS styling is not loading properly. Image: https://i.stack.imgur ...