Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style a disabled checkbox?

Tags:

html

css

Do you know how I could style a checkbox when it is disabled?

E.g.:

<input type="checkbox" value="All Terrain Vehicle"        name="exfilter_All Terrain Vehicle"        id="exfilter_All_Terrain_Vehicle"        class="exfilter" disabled=""> 
like image 228
Ozzy Avatar asked Nov 24 '10 20:11

Ozzy


People also ask

How do I style a disabled checkbox?

You can't style a disabled checkbox directly because it's controlled by the browser / OS. However you can be clever and replace the checkbox with a label that simulates a checkbox using pure CSS. You need to have an adjacent label that you can use to style a new "pseudo checkbox".

How do I make checkboxes disabled in CSS?

You can put a transparent div on top of the checkbox to make it un-clickable by toggling a class on the parent object. Something like this... Show activity on this post. This still sets the css styles for the checkboxes so it looks like it was clicked.


1 Answers

Use the attribute selector in the css

input[disabled]{   outline:1px solid red; // or whatever } 

for checkbox exclusively use

input[type=checkbox][disabled]{   outline:1px solid red; // or whatever } 

$('button').click(function() {    const i = $('input');      if (i.is('[disabled]'))      i.attr('disabled', false)    else      i.attr('disabled', true);  })
input[type=checkbox][disabled] {    outline: 2px solid red;  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <input type="checkbox" value="tasd" disabled />  <input type="text" value="text" disabled />  <button>disable/enable</button>
like image 129
Gabriele Petrioli Avatar answered Sep 22 '22 07:09

Gabriele Petrioli