I have the following mark-up using the bootstrap framework.
<div class="col-md-4">
<div class="custom-container">
<img class="center-block img-responsive img-circle invite-contact-trybe" src="{$img}" alt="Contact Image">
<input class="invite-contact-checkbox" type="checkbox">
</div>
</div>
I would like to achieve the following:
Is there anyway to do this using CSS?
I would obviously need 3 states:
Initial:
.custom-container input[type=checkbox]{}
Some form of hover state:
.custom-container input[type=checkbox]:hover{}
When it is checked:
.custom-container input[type=checkbox]:checked{}
Can anyone suggest a solution?
Background image checkbox replacement
Let's create this
This is a very simple example using a
:before
pseudo element as well as:checked
and:hover
states.With this clean HTML
Note the matching
for
andid
attributes, this attaches the label to the checkbox. Also, the order of elements is very important; the label must come after the input so we can style withinput:checked
As well as this Basic CSS
The checkbox is hidden with
display: none
and all interaction is done with the labelThe
:after
pseudo element is given a unicode tick (\2714
) but this could also be ticked with a background image.The jagged edge caused by the border-radius can be softened by a matching color
box-shadow
. The inside edge of the border looks fine when the background image is not a solid block of color.The
transition: all 0.4s
creates a smooth fade in / out for the border.I have added more guidance in CSS comments.
Complete Example