gpt4 book ai didi

html - 无法在 css 中为下拉列表应用样式

转载 作者:太空宇宙 更新时间:2023-11-04 01:19:37 25 4
gpt4 key购买 nike

您好,我正在尝试使用 CSS 类设计多选下拉列表。我正在尝试开发正下方的多选下拉列表框。

enter image description here

我有下面的 html 代码。

.checkbox {
position: relative;
display: block;
margin-top: 10px;
margin-bottom: 10px;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
min-width: 150px;
max-height: 600px;
overflow-x: visible;
overflow-y: visible;
padding: 0;
margin: 0;
list-style: none;
font-size: 13px;
font-weight: 500;
text-align: left;
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
-webkit-background-clip: padding-box;
background-clip: padding-box;
color: #464646;
}

.btn-group, .btn-group-vertical {
position: relative;
display: inline-block;
vertical-align: middle;
}
toggle.btn-default {
background: #dedede;
background: rgba(0, 0, 0, 0.13);
border: 1px solid #2E92FA;
color: #464646;
outline: none;
}
<div class="btn-group open">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="true">Filter by<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" style="width:100%;">
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Sensors</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" checked="checked" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Actuators</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" checked="checked" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Digital inputs</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Outputs</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Converters</label>
</div>
</li>
</ul>
</div>

在上面的代码中,复选框出现在中间并单击下拉菜单,它应该展开,默认情况下它不应该展开。有人可以帮助我按预期完成这项工作吗?任何帮助,将不胜感激。谢谢。

最佳答案

首先尝试删除 open 类。

$('.btn-group').click(function(e) { $('.dropdown-menu').toggleClass('open'); });
body {
margin:0;
}
.checkbox {
position: relative;
display: block;
margin-top: 10px;
margin-bottom: 10px;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
min-width: 150px;
max-height: 600px;
overflow-x: visible;
overflow-y: visible;
padding: 0;
margin: 0;
list-style: none;
font-size: 13px;
font-weight: 500;
text-align: left;
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
-webkit-background-clip: padding-box;
background-clip: padding-box;
color: #464646;
transition:all .3s;
transform: translate(-100%);
}
.dropdown-menu.open {
transform: translate(0%);
}
.btn-group, .btn-group-vertical {
position: relative;
display: inline-block;
vertical-align: middle;
}
toggle.btn-default {
background: #dedede;
background: rgba(0, 0, 0, 0.13);
border: 1px solid #2E92FA;
color: #464646;
outline: none;
}
label.checkbox-inline {
display: contents;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="true">Filter by<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" style="width:100%;">
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox17" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox17">Sensors</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" checked="checked" id="inlineCheckbox18" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox18">Actuators</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" checked="checked" id="inlineCheckbox19" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox19">Digital inputs</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox20" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox20">Outputs</label>
</div>
</li>
<li>
<div class="checkbox" style="margin-left:25px">
<input type="checkbox" id="inlineCheckbox21" value="option1">
<label style="margin-left:-30px; margin-right:30px;" class="checkbox-inline" for="inlineCheckbox21">Converters</label>
</div>
</li>
</ul>
</div>

关于html - 无法在 css 中为下拉列表应用样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49355753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com