Reputation: 247
I am building a form using Contact Form 7 in Wordpress which has a few radio inputs. I would like to have near every single radio button a small image (some kind of label which shows a fabric texture).
Has anyone an idea how can I achieve this?
Maybe there is some working plugins like ACF, which are compatible with CF7 or jQuery snippet which insert single html line with <img>
tag.
I would need a layout like this one:
Upvotes: 0
Views: 11928
Reputation: 648
Wasim's solution works but if you need to make it with img tag, you can use this:
$(".radio-image span span").unwrap(); //Remove spans between input and label tags
$(".wpcf7-list-item-label").remove(); //Remove the label that added by Contact Form 7
$(".radio-image input+label").each(function () {
const id = $(this).prop("for");
$(this).parent().find("input").attr("id", id);
});
This is markup for Contact Form 7
<div class="radio-image">
[radio radio-name "Value"]
<label for="label-1"><img src="path/to/image.jpg"></label>
</div>
The rest is CSS work.
.radio-image {
margin-top: 20px;
border: 1px solid rgba(0, 0, 0, 0.2);
img {
width: 100%;
height: 100%;
object-fit: cover;
cursor: pointer;
}
[type="radio"] {
display: none;
+ label {
position: relative;
&:before {
content: "";
position: absolute;
top: -5px;
left: -5px;
border-radius: 50%;
background: $white;
width: 20px;
height: 20px;
z-index: 2;
border: 1px solid rgba(0, 0, 0, 0.3);
box-shadow: 0 0 0 5px $white;
}
&:after {
content: "";
width: 12px;
height: 12px;
background: $primary-color;
border-radius: 50%;
position: absolute;
top: 5px;
left: 5px;
transform: translateX(-50%) translateY(-50%);
display: none;
z-index: 3;
}
}
&:checked + label::after {
display: block;
}
&:checked + label img {
filter: grayscale(0) !important;
}
}
}
Upvotes: 1
Reputation: 611
Contact form 7 has unique id or class for every input field, you can target that class or ID to add stylings
I have done this sample to show the process, your code may be different than this
<input class="radio1" type="radio">
CSS:
input.radio1 {
height: 50px;
width: 50px;
display: block; /* You Can remove display block, since your buttons are already stacked */
}
input.radio1:after {
background-image: url('images/image.img');
content: '';
width: 50px;
height: 50px;
display: inline-block;
background-size: cover;
margin-left: 35px;
}
or simply you can apply the background image to that green box if you are already planning to make it look that way.
Upvotes: 7