【发布时间】:2021-07-14 16:10:32
【问题描述】:
我有一个自定义 CSS 复选框,如下所示:https://jsfiddle.net/apewjcg9/
不要太担心事物的定位和大小。我的主要问题是在将鼠标悬停在复选框上时处理添加缓入过渡。如您所见,悬停时,我将边框应用于框本身。但是,我想为该边框提供一个小的缓入过渡效果。无论我尝试了什么,似乎都没有应用过渡。
HTML
<input type="checkbox" class="checkbox" id="myCheckbox" />
<label class="checkboxLabel" for="myCheckbox">This is a checkbox label</label>
CSS
.checkbox {
opacity: 0;
position: absolute;
}
.checkbox + .checkboxLabel::before {
background-color: white;
border: 1px solid black;
border-radius: 2px;
content: '';
display: inline-block;
height: 18px;
width: 18px;
font-size: 16.5px;
text-align: center;
vertical-align: top;
margin-right: 5px;
}
.checkbox:checked + .checkboxLabel::before {
background-color: firebrick;
border-radius: 2px;
color: white;
content: '\2713';
font-size: 19px;
line-height: 18px;
}
.checkboxLabel {
cursor: pointer;
display: inline-block;
margin: 0;
}
.checkbox:hover + .checkboxLabel::before {
border: 1.5px solid firebrick;
box-sizing: border-box;
}
我已经尝试将transition: border 1s 添加到.checkbox + .checkboxLabel::before,添加到标签本身,添加到输入中,但没有任何效果可以实现轻松过渡。
【问题讨论】:
标签: css