这里的简短回答是,您需要了解 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