我正在使用Wordpress中的Contact Form7构建一个表单,它有几个无线输入。我希望在每个单选按钮附近有一个小图像(某种标签,显示织物纹理)。有没有人知道我怎么才能做到这一点?也许有一些像ACF这样的工作插件,它与CF7或jQuery代码片段兼容,可以插入带有<img>标签的单个html行。
我需要一个像这样的布局:

发布于 2019-01-30 02:19:55
Contact form 7对每个输入字段都有唯一的id或类,您可以针对该类或ID添加样式
我已经做了这个例子来展示这个过程,你的代码可能与下面的不同
<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;
}

或者,如果你已经计划让它看起来是那样的话,你可以简单地将背景图像应用到那个绿色的盒子上。
发布于 2020-05-06 03:05:52
Wasim的解决方案可以工作,但如果你需要使用img标签,你可以使用以下代码:
$(".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);
});这是联系人表单7的标记
<div class="radio-image">
[radio radio-name "Value"]
<label for="label-1"><img src="path/to/image.jpg"></label>
</div>剩下的就是CSS工作了。
.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;
}
}
}https://stackoverflow.com/questions/54426310
复制相似问题