What methods can be used to alter the appearance of a disabled and checked checkbox?

Is there a way to change the appearance of my enabled and disabled checkboxes to be green? I've tried adjusting various CSS properties but so far have only been able to change the outline color. Any tips on how to make the checkbox itself appear green or where to find some predefined images like this one: https://i.sstatic.net/5VHGz.png ?

Sample HTML code:

<label>
    <input type="checkbox" ng-model="t.isCorrected" disabled/> 
    {{('sth.isCorrectedLabel') | translate}}
</label>

Corresponding CSS code:

input[type=checkbox][disabled]:checked {
    outline:2px solid green;
    accent-color: green !important;
    background-color: #FA9E57 !important;
}

Answer №1

This particular query is reminiscent of a past one titled "How to set CSS for disabled checkboxes?", but with subtle differences. Nonetheless, the solution may overlap depending on individual requirements (for all those seeking answers), thus warranting its inclusion here.

Workaround for Achieving Green Checkbox in Edge Browser

In an attempt to customize a disabled checkbox to display as green while ensuring compatibility with the Edge browser, I experimented with various suggested solutions without success. It appeared that Edge tends to override any styling applied to disabled checkboxes. Nevertheless, I devised a workaround that mimics the appearance and functionality of a disabled checkbox effectually. By temporarily removing the disabled attribute, setting Accent-color to green, and incorporating an onclick function to toggle the check status of the control, the desired result was attained.

https://i.sstatic.net/tCPVp4Oy.gif

CSS

input[type="checkbox"] {
    Accent-color: green
}

HTML

<input type='checkbox' checked id="checkbox-1" onclick="keepCheckboxGreen('checkbox-1')">

JavaScript

function keepCheckboxGreen(id) {
    var checkbox = document.getElementById(id);
    checkbox.checked = !checkbox.checked;
}

This approach enables the application of preferred styles with no impact from user interaction.

Answer №2

Presented here is a unique solution employing CSS to incorporate an image of a checkbox into the parent element of the input. The customization in this scenario is tailored specifically for a disabled, checked checkbox.

/* Styling to include custom checkbox in container with disabled, checked state */
.checkbox-container:has(> input:disabled:checked)::after {
    width: 10px;
    height: 10px;
    font-size: 9px;
    background: green;
    display: inline-block;
    border: 1px solid #000000;
    border-radius: 3px;
    color: white;
    position: relative;
    content: "✔";
    text-align: center;
    float: left;
    margin: 3px 4px 0 5px;
}

/* Hiding default appearance of disabled, checked checkbox */
.checkbox-container input:disabled:checked {
    display: none
}
Updated styling:

<div class="checkbox-container">
  <input type="checkbox" id="cb-enabled-1"  checked="checked"/><label for="cb-enabled-1">Enabled Checkbox</label>
</div>
<div class="checkbox-container">  
  <input type="checkbox" id="cb-disabled-unchecked-1" disabled="disabled" /><label for="cb-disabled-unchecked-1">Disabled Checkbox - Unchecked</label>  
</div>
<div class="checkbox-container">  
  <input type="checkbox" id="cb-disabled-checked-1" checked="checked" disabled="disabled"/><label for="cb-disabled-checked-1">Disabled Checkbox - Checked</label>    
</div>

<br>
Default Browser Appearance:
<div>
  <input type="checkbox" id="cb-enabled-2"  checked="checked"/><label for="cb-enabled-2">Enabled Checkbox</label>
</div><div>  
  <input type="checkbox" id="cb-disabled-unchecked-2" disabled="disabled" /><label for="cb-disabled-unchecked-1">Disabled Checkbox - Unchecked</label>  
</div><div>    
  <input type="checkbox" id="cb-disabled-checked-2" checked="checked" disabled="disabled" /><label for="cb-disabled-checked-2">Disabled Checkbox - Checked</label>    
</div>  

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

Angular translation: Utilizing variable substitution along with date filtering

I'm trying to apply a filter to the dynamic translate variable. Here is the code I am currently using: {{'REGISTER_PAGE_USER.BIRTHDAY_MIN_DATE' | translate:'{ minimum: (minDate | date:'MMMM dd yyyy') }'}} Unfortunate ...

Having trouble with adjusting the width of an absolutely positioned image using animation

Currently, I am using jQuery version 10.4.2 and I am trying to smoothly scale up an image that is absolute positioned. However, despite not encountering any errors with the code below, the animation does not happen as expected. Instead, the image suddenly ...

Choose the grandparent of an element's parent

Is there a way to select the grandparent element of a child in Javascript without having to chain the .parentElement method twice? Specifically, I am looking for a method that can substitute .parentElement.parentElement when selecting the desired element, ...

How to showcase the data retrieved via BehaviorSubject in Angular

I've been working on retrieving data from an API using a service and passing it to components using BehaviorSubject in order to display it on the screen: Here is the service code snippet: @Injectable({ providedIn: 'root', }) export clas ...

Add a class to a particular element within an ngFor loop

I wrote a loop that creates names along with icons. My goal is to make the icon appear only when it is hovered over. <div class="elm" *ngFor="let element of callWorkflowData?.jobsList"> <mat-card (mouseover)="hover=true" (mouseleave)="hover= ...

Angular 2 is throwing an error message stating that Foods.filter is not recognized as a function

Whenever I attempt to delete multiple items by selecting checkboxes, I encounter the error Foods.filter is not a function in my console. Strangely, this error only occurs when I include a pipe in the HTML table. Without the pipe, everything functions as ex ...

I'm curious about the significance of the "packages" property in the requireJs config. Can someone explain how it functions?

I'm currently trying to grasp the concept of requireJs and its functionality. In my exploration, I encountered a configuration property called "packages." From what I gather, 'packages' is intended for specifying a complete folder or module ...

Angular two-way selection of dependent dropdowns

I am working on creating a dependent select/dropdown feature. Here is a sample JSON data that I have: [ { "id": 15695, "username": "user1", "address": { "id": 16794, "location": "O Treviño de San Pedro" }, "jobs": [ ...

Passing data from the Config Controller in AngularJS to another ControllerAre you looking to

I am facing an issue where I need to transfer data from the control (within config) to an external controller. I have attempted to use a factory to pass the data, but even after the data is modified, it still remains as 0 (I'm not sure what went wrong ...

Hide the border on a table with CSS

I recently installed a Wordpress Template and customized the table's background and text colors. However, I am struggling to remove the border around the table. Despite searching for solutions, my limited CSS knowledge has not led me to a fix that wor ...

Transform this color matching game into an image matching game using JavaScript and jQuery

I have a color matching game that I would like to enhance by matching background-images instead of just background-colors. However, I am facing difficulties in making this change. For instance, instead of matching the color red with the text "red," I wan ...

Creating a dynamic side navigation menu that adjusts to different screen sizes

I have been working on a project's webpage that was initially created by another Software Engineer. After he left, I continued to work on the webpage. The issue I encountered is that he preferred a side menu over a navbar using the left-panel and righ ...

Mastering the Art of JSON Conversion for AngularJS

Is there a way to transform the following JSON data structure [{"categories":[{"id":"171","name":"Fashion"},{"id":"219","name":"Blog"}]}] into this format? [{"id":"171","name":"Fashion"},{"id":"219","name":"Blog"}] This change is necessary for proper ...

Place a picture within a specified View

I am encountering an issue with my profile image in the header component. The source of the image is coming from the database as a string array. However, when I fetch the user picture from the database, it appears slightly cut off from the top, giving the ...

"Recently, I included a function called 'test' in the code, but I encountered an error stating that it was not recognized as a function. Can someone provide assistance

Issue Detected A 'TypeError' has been thrown: ".goal_test".click is not defined as a function Feel free to collaborate on the code by clicking this link: Please note that my modified code is enclosed within asterisk symbols. ...

Setting the Minimum Width of Floating Columns in HTML and CSS

Can anyone provide some assistance? I am currently using a design that I want to modify so that the columns do not compress or shrink below a certain size. I have attempted to use "min-width" without success. Any help would be greatly appreciated. Thank y ...

What could be the reason for the sudden halt in updates to my bootstrap.css file

Incorporated Bootstrap into my ASP.NET MVC project. Made a single tweak to the bootstrap.css file, but the update is not reflecting. Even in debug mode, it seems like nothing has changed. I faced a similar scenario before where changes weren't reflect ...

Sort products by the subcategory in Firebase

I am currently facing a challenge in filtering products based on their sub child nodes within Firebase. This is how my data is structured: products/ product1 /author: 12345 /title: "Awesome" /description: "more awesome" ...

tips for creating a jquery/css scales animation

I am looking to implement a unique feature on my website where I create scales with a balancing effect. The scales should mimic an up and down motion continuously. You can see an example of what I'm referring to here Is there a way in jQuery or CSS t ...

Tips for Automatically Loading Dependencies in AngularJS

Currently, I am working on an Angular application where I am designing various widgets using HTML5. Here is a snippet of the code structure: <html ng-app> <div ng-controller="widget1"> </div> <div ng-controller="widget2"> ...