Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add strikethrough to checked checkbox

I am trying to add strikethrough when i select a checkbox in my form (Bootstrap v3). I coded this bootply:

<div class="form-group ">
    <label for="inputName" class="col-md-1 control-label">select</label>  
    <div class="col-md-5">
        <div class="checkbox">
             <label><input type="checkbox" name="packersOff" class="strikethrough" value="1">sssssssss</label>
        </div>
     </div>
</div>

and added a class in css

.strikethrough:checked{
  text-decoration:line-through;
}

but it doesn't work..

like image 696
yaylitzis Avatar asked Jun 22 '15 08:06

yaylitzis


People also ask

How do I add a border to a checkbox?

Style the label with the width, height, background, margin, and border-radius properties. Set the position to "relative". Style the "checkbox-example" class by setting the display to "block" and specifying the width and height properties. Then, specify the border-radius, transition, position, and other properties.

How do I add color to a checkbox?

To style the checkbox the user first needs to hide the default checkbox which can be done by setting the value of the visibility property to hidden. Example 1: Consider the example where HTML checkbox is styled using CSS. When the user clicks the checkbox, the background color is set to green.


1 Answers

Here is a solution to put a strike through when your input is checked:

input[type=checkbox]:checked + label.strikethrough{
  text-decoration: line-through;
}
<div class="form-group ">
    <label for="inputName" class="col-md-1 control-label">select</label>  
    <div class="col-md-5">
        <div class="checkbox">
            <input type="checkbox" name="packersOff" id="packers" value="1"/>
            <label for="packers" class="strikethrough">sssssssss</label>
        </div>
     </div>
</div>

JSFIDDLE

With this solution when ever the checkbox is checked it will do something to the label. so you could make it bold or change its colour if you wanted.

like image 133
Andrew Avatar answered Oct 19 '22 22:10

Andrew