使用 i 标签而不是下拉按钮的背景 属性 切换效果
Toggle effect using i tag instead of the background property for a dropdown button
我对不需要 JS 的下拉菜单很感兴趣。我在网上找到了一些资源并成功了。但是,我想通过 i 标签(或任何更好的建议)更改我用作下拉列表 "buttons" 的图像,以便我可以使用 font-awesome/line-awesome 类 代替(获取 .svg 需要据我所知付费许可证)。
我不知道如何处理 input:checked ~ label 如果选择
<label for="dropOptsPost"><i class="fa fa-ellipsis-v"></i></label>
.dropdown label {
display: block;
cursor: pointer;
background: url(img/closed.png) no-repeat left center;
padding: 3rem 0 3rem 8rem;
}
/* Toggle effect */
input:checked ~ label {
background: url(img/open.png) no-repeat left center;
}
input:checked ~ .dropdown-content {
max-height: 100%;
}
<div class="dropdown drop-container">
<input type="checkbox" id="dropdownMenu">
<label for="dropdownMenu"></label>
<div class="dropdown-content">
<a href="#" title="">Option 1</a>
<a href="#" title="">Option 2</a>
<a href="#" title="">Option 3</a>
</div>
</div>
更新
请在下面的类似示例中查看我的解决方案
$(document).ready(function() {
$('.toggle').click(function() {
$(this).find('.toggle-icon').toggleClass('fa-plus-circle fa-times active');
$('.toggle').toggleClass('active');
$('.toggle-content').toggleClass('active');
});
});
.hidden {
overflow: hidden;
}
.container {
width: 100%;
height: 1000px;
margin: 0 auto;
background-color: #eee;
}
.wrapper {
background-color: pink;
position: relative;
display: flex;
align-items: center;
}
.toggle {
display: block;
width: 20px;
height: 20px;
float: left;
cursor: pointer;
color: white;
text-align: center;
background-color: green;
margin: 10px;
}
.toggle-icon {
color: white;
font-size: 10px;
text-align: center;
}
.toggle.active {
background-color: red;
}
.toggle-content {
display: none;
}
.toggle-content.active {
display: block;
background-color: white;
border: 1px solid black;
position: absolute;
top: 40px;
left: 0;
}
<div class="container">
<div class="wrapper">
<div class="toggle"><a href="javascript:void"><i class="toggle-icon fas fa-cogs"></i></a></div>
<div class="toggle-content">
<p>Some content</p>
</div>
</div>
</div>
我对不需要 JS 的下拉菜单很感兴趣。我在网上找到了一些资源并成功了。但是,我想通过 i 标签(或任何更好的建议)更改我用作下拉列表 "buttons" 的图像,以便我可以使用 font-awesome/line-awesome 类 代替(获取 .svg 需要据我所知付费许可证)。
我不知道如何处理 input:checked ~ label 如果选择
<label for="dropOptsPost"><i class="fa fa-ellipsis-v"></i></label>
.dropdown label {
display: block;
cursor: pointer;
background: url(img/closed.png) no-repeat left center;
padding: 3rem 0 3rem 8rem;
}
/* Toggle effect */
input:checked ~ label {
background: url(img/open.png) no-repeat left center;
}
input:checked ~ .dropdown-content {
max-height: 100%;
}
<div class="dropdown drop-container">
<input type="checkbox" id="dropdownMenu">
<label for="dropdownMenu"></label>
<div class="dropdown-content">
<a href="#" title="">Option 1</a>
<a href="#" title="">Option 2</a>
<a href="#" title="">Option 3</a>
</div>
</div>
更新 请在下面的类似示例中查看我的解决方案
$(document).ready(function() {
$('.toggle').click(function() {
$(this).find('.toggle-icon').toggleClass('fa-plus-circle fa-times active');
$('.toggle').toggleClass('active');
$('.toggle-content').toggleClass('active');
});
});
.hidden {
overflow: hidden;
}
.container {
width: 100%;
height: 1000px;
margin: 0 auto;
background-color: #eee;
}
.wrapper {
background-color: pink;
position: relative;
display: flex;
align-items: center;
}
.toggle {
display: block;
width: 20px;
height: 20px;
float: left;
cursor: pointer;
color: white;
text-align: center;
background-color: green;
margin: 10px;
}
.toggle-icon {
color: white;
font-size: 10px;
text-align: center;
}
.toggle.active {
background-color: red;
}
.toggle-content {
display: none;
}
.toggle-content.active {
display: block;
background-color: white;
border: 1px solid black;
position: absolute;
top: 40px;
left: 0;
}
<div class="container">
<div class="wrapper">
<div class="toggle"><a href="javascript:void"><i class="toggle-icon fas fa-cogs"></i></a></div>
<div class="toggle-content">
<p>Some content</p>
</div>
</div>
</div>