Create a more beautiful checkbox

The browser's default checkbox is too ugly, especially in dark mode
This commit is contained in:
Cotes Chung 2020-12-14 00:24:33 +08:00
parent d0a8d072fd
commit d61446fafc
6 changed files with 65 additions and 10 deletions

View file

@ -864,16 +864,46 @@ div.post-content .table-wrapper {
ul {
&.task-list, &:not([class]) {
padding-left: 2rem;
.task-list-item {
list-style-type: none;
}
// attribute 'hide-bullet' added by JS
.task-list-item[hide-bullet] {
list-style-type: none;
> span { // <span> created by JS
border: 1px solid var(--checkbox-color);
background-color: var(--checkbox-bg);
border-radius: 4px;
margin: 0 .5rem .2rem -1.5rem;
vertical-align: middle;
height: 1rem;
width: 1rem;
display: inline-block;
&[checked] {
background-color: var(--checkbox-checked-bg);
&::after {
content: "";
width: 5px;
height: 9px;
position: relative;
bottom: 9px;
left: 5px;
background: var(--checkbox-checked-bg);
display: inline-block;
border: solid var(--checkbox-checked-color); // the hook symbol
border-width: 0 2px 2px 0;
transform: rotate(45deg) scale(1);
}
}
}
} // .task-list-item
input[type=checkbox] {
margin: 0 .5rem .25rem -1.3rem;
vertical-align: middle;
}
display: none;
}
} // ul
} // .post-content

View file

@ -32,6 +32,11 @@
--btn-box-shadow: var(--main-wrapper-bg);
--card-header-bg: rgb(51, 50, 50);
--label-color: rgb(108, 117, 125);
--checkbox-color: var(--text-color);
--checkbox-bg: var(--main-wrapper-bg);
--checkbox-checked-color: var(--main-wrapper-bg);
--checkbox-checked-bg: var(--text-color);
/* Sidebar */
--nav-cursor-color: rgb(183, 182, 182);

View file

@ -25,6 +25,11 @@
--btn-backtotop-color: #686868;
--btn-backtotop-border-color: #f1f1f1; //--main-border-color,
--btn-box-shadow: #eaeaea;
--checkbox-color: darkgrey;
--checkbox-bg: var(--main-wrapper-bg);
--checkbox-checked-bg: var(--main-wrapper-bg);
--checkbox-checked-color: grey;
/* Sidebar */
--sidebar-bg: radial-gradient(

View file

@ -30,13 +30,14 @@ $prompt-newer: "{{ site.data.label.post.button.next }}";
.post-content {
> ol, > ul, > dl {
padding-left: 2rem;
li+li {
li + li {
margin-top: 0.3rem;
}
}
li {
> ol, > ul, > dl { // sub list
padding-left: 2rem;
margin-top: 0.3rem;
}
> p {
margin: 1rem 0 0.8rem;

View file

@ -18,4 +18,6 @@
{% include_relative _commons/copy-link.js %}
{% include_relative _commons/checkbox.js %}
{% include_relative _utils/tooltip-loader.js %}

View file

@ -0,0 +1,12 @@
/*
* Create a more beautiful checkbox
*/
$(function() {
/* hide bullet of checkbox item */
$("li.task-list-item:has(input)").attr("hide-bullet", "");
/* create checked checkbox */
$("input[type=checkbox][checked=checked]").before("<span checked></span>");
/* create normal checkbox */
$("input[type=checkbox]:not([checked=checked])").before("<span></span>");
});