我不是css专家,所以请原谅我.我正在try 做一个定制的下拉列表,它的高度可以动态地适应li
的数字.我当前的代码不适合li
,即使下拉高度设置为fit-content
.我怎么才能解决这个问题呢?
EDIT:我没有使用min-height属性,因为我希望无论内容包含2个li
还是50个li
,都能无缝匹配
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100%x;
height: 90px;
background-color: green;
}
.dropdownCon {
display: flex;
flex-direction: column;
height: 50px;
}
.dropdownBtn {
display: flex;
justify-content: center;
align-items: center;
font-size: 19px;
font-weight: 600;
font-family: sans-serif;
color: #ffffff;
padding: 11px 23px 11px 23px;
background-color: #121212;
border-radius: 5px;
border: 1px solid #ffffff;
cursor: pointer;
}
.dropdown {
width: 100%;
height: fit-content;
max-height: 250px;
overflow-y: auto;
background-color: blue;
}
.dropdown ul {
width: 100%;
height: 100%;
margin: 0%;
padding: 0%;
}
.dropdown ul li {
display: flex;
column-gap: 10px;
align-items: center;
width: 100%;
height: 30px;
font-size: 16px;
font-weight: 500;
font-family: sans-serif;
color: #ffffff;
border-bottom: 1px solid #c1c1c1;
cursor: pointer;
}
<div class="wrapper">
<div class="dropdownCon">
<div class="dropdownBtn">
dropdown
</div>
<div class="dropdown">
<ul>
<li>
test
</li>
<li>
test
</li>
<li>
test
</li>
<li>
test
</li>
<li>
test
</li>
<li>
test
</li>
</ul>
</div>
</div>
</div>