【问题标题】:Creating a check-box list in elementor / wordpress [closed]在elementor / wordpress中创建复选框列表[关闭]
【发布时间】:2020-05-01 02:08:10
【问题描述】:

我想在 elementor / wordpress 中制作一个复选框列表,我的愿景是它应该看起来很像 google keep 中的“列表”选项,其中行在另一端有复选框,当单击文本时变成删除线。

它不需要像谷歌那样花哨的动画(除非它们很容易实现)。

我已经搜索了很多,但还没有找到通过 elementor 本身或可能能够做到这一点的插件的方法(我发现的只是有关表单和登录时“记住我”类型复选框的东西表格)。

所以我想从你那里得到关于我应该如何进行的指导。

我可以在 CSS 中做这种事情吗? - 如果可以,我需要学习什么?

我需要创建一个自定义插件,然后将其添加为简码吗?

提前谢谢大家!

【问题讨论】:

    标签: css wordpress elementor


    【解决方案1】:

    这里的简短回答是,您需要了解 html、css、javascript 和可能的 php 的一些基础知识,具体取决于确切的功能以及您希望如何部署它。

    长答案,可以通过 html & css 来设计和设置复选框的样式。您需要 js 在单击后使文本删除线。如果您想在页面重新加载时保存选中状态,您需要创建一个 cookie,或者通过 javascript 将其保存到 localStorage。当然,除非您想将其保存到数据库中,这对您的网站来说会更安全,但需要使用 PHP 和 MySQL 将选中状态和删除线状态提交到 Wordpress 数据库。

    这是一个粗略的复选框,可以满足您的基本需求

    HTML:

    <div class="wrapper">
      <div class="container">
       <label class="checkbox-label">
                <input onclick="strikethrough()" type="checkbox" id="mycheckbox1" name="mycheckbox1" value="yes">
                <span class="checkbox-custom rectangular"></span>
            </label>
    </div>
    </div>
    <div class="text">
        <h2 id="changeText1">Hello World</h2>
    </div>
    

    CSS:

    @import url('https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900');
    body {
        font-family: 'Roboto', sans-serif;
      }
    
    .card {
        width: 50px;
        margin: 0 auto;
        clear: both;
        display: block;
        padding: 0px 0px;
        border-radius: 4px;
    }
    .card::after {
        clear: both;
        display: block;
        content: "";
    }
    .card .checkbox-container {
        width: 100%;
        box-sizing: border-box;
        text-align:center;
      padding: 10px 0px;
    }
    
    
    /* Styling Checkbox Starts */
    .checkbox-label {
        display: block;
        position: relative;
        margin: auto;
        cursor: pointer;
        font-size: 22px;
        line-height: 24px;
        height: 24px;
        width: 24px;
        clear: both;
    }
    
    .checkbox-label input {
        position: absolute;
        opacity: 0;
        cursor: pointer;
    }
    
    .checkbox-label .checkbox-custom {
        position: absolute;
        top: 0px;
        left: 0px;
        height: 24px;
        width: 24px;
        background-color: transparent;
        border-radius: 5px;
        transition: all 0.3s ease-out;
        -webkit-transition: all 0.3s ease-out;
        -moz-transition: all 0.3s ease-out;
        -ms-transition: all 0.3s ease-out;
        -o-transition: all 0.3s ease-out;
        border: 2px solid #D4AF37;
    }
    
    
    .checkbox-label input:checked ~ .checkbox-custom {
        background-color: #FFFFFF;
        border-radius: 5px;
        -webkit-transform: rotate(0deg) scale(1);
        -ms-transform: rotate(0deg) scale(1);
        transform: rotate(0deg) scale(1);
        opacity:1;
        border: 2px solid #D4AF37;
    }
    
    
    .checkbox-label .checkbox-custom::after {
        position: absolute;
        content: "";
        left: 12px;
        top: 12px;
        height: 0px;
        width: 0px;
        border-radius: 5px;
        border: solid #D4AF37;
        border-width: 0 3px 3px 0;
        -webkit-transform: rotate(0deg) scale(0);
        -ms-transform: rotate(0deg) scale(0);
        transform: rotate(0deg) scale(0);
        opacity:1;
        transition: all 0.3s ease-out;
        -webkit-transition: all 0.3s ease-out;
        -moz-transition: all 0.3s ease-out;
        -ms-transition: all 0.3s ease-out;
        -o-transition: all 0.3s ease-out;
    }
    
    
    .checkbox-label input:checked ~ .checkbox-custom::after {
      -webkit-transform: rotate(45deg) scale(1);
      -ms-transform: rotate(45deg) scale(1);
      transform: rotate(45deg) scale(1);
      opacity:1;
      left: 8px;
      top: 3px;
      width: 6px;
      height: 12px;
      border: solid #51B4A6;
      border-width: 0 3px 3px 0;
      background-color: transparent;
      border-radius: 0;
    }
    #changeText1 {
      text-align:center;
    }
    
    

    JS:

    function strikethrough(){
        var ele = document.getElementById("changeText1");
        var checkBox = document.getElementById("mycheckbox1");
        if (checkBox.checked == true){
        ele.style.setProperty("text-decoration", "line-through");}
        else {
            ele.style.setProperty("text-decoration", "none");
        }
    }
    

    工作示例:https://codepen.io/alexhbryant/pen/dyYVbjK

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 2016-02-29
      • 1970-01-01
      • 2014-12-31
      • 2014-06-12
      • 2015-05-22
      相关资源
      最近更新 更多