首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Contact form 7将图像添加到每个无线输入

Contact form 7将图像添加到每个无线输入
EN

Stack Overflow用户
提问于 2019-01-30 01:13:37
回答 2查看 6.3K关注 0票数 0

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

我需要一个像这样的布局:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-30 02:19:55

Contact form 7对每个输入字段都有唯一的id或类,您可以针对该类或ID添加样式

我已经做了这个例子来展示这个过程,你的代码可能与下面的不同

代码语言:javascript
复制
<input class="radio1" type="radio">

CSS:

代码语言:javascript
复制
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;
}

或者,如果你已经计划让它看起来是那样的话,你可以简单地将背景图像应用到那个绿色的盒子上。

票数 5
EN

Stack Overflow用户

发布于 2020-05-06 03:05:52

Wasim的解决方案可以工作,但如果你需要使用img标签,你可以使用以下代码:

代码语言:javascript
复制
$(".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的标记

代码语言:javascript
复制
    <div class="radio-image">                
        [radio radio-name "Value"]
        <label for="label-1"><img src="path/to/image.jpg"></label>
    </div>

剩下的就是CSS工作了。

代码语言:javascript
复制
.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;
    }
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54426310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档