【发布时间】:2021-01-21 00:47:41
【问题描述】:
我想创建一个切换button,将其形状从加号变为减号。
仅使用 CSS,不使用伪元素。
我的想要的效果是让“+”号中的垂直线收缩成水平线。
我知道这是可能的,但我不确定哪条是最好的选择。我正在考虑用height 做点什么,但我担心浏览器的line-height 会改变它在元素中的位置。
$('button').on("click", function(){
$(this).toggleClass('active');
});
button {
color: #ecf0f1;
background: #e74c3c;
width: 50px;
height: 50px;
border: 0;
font-size: 1.5em;
}
button span {
transition: all .75s ease-in-out;
}
button.active span {
/* Code to morph + to - */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button><span>+</span></button>
【问题讨论】:
标签: javascript html jquery css css-transitions