【发布时间】:2020-03-02 08:16:49
【问题描述】:
我需要一个自定义组合框。所以,我用ul 实现了。问题是我无法通过单击button 在顶部打开组合框列表。在显示ul 时,它会将button 移动到网页底部。
代码:
ul{
width: 100px;
background-color: rgb(224, 224, 224);
border-radius: 4px;
border: 1px solid black;
padding: 0;
margin: 0;
}
ul li{
list-style: none;
cursor: pointer;
padding: 4px 10px;
}
li:hover{
background-color: white;
}
div{
width: 100%;
height: 40px;
background-color: bisque;
}
section{
height: 400px;
background-color: #525252;
}
button{
width: 100px;
height: 100%;
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section>
<p>Some content</p>
</section>
<div>
<ul>
<li>Parrot</li>
<li>Dog</li>
<li>Cat</li>
<li>Squirrel</li>
<li>Otter</li>
<li>Cow</li>
<li>Goat</li>
<li>Finch</li>
</ul>
<button onclick="showPop()">Pet</button>
</div>
<script>
let ul = document.getElementsByTagName('ul')[0]
onload = function(){
ul.style.display = 'none'
}
function showPop(){
if(ul.style.display == 'none'){
ul.style.display = 'block'
}else{
ul.style.display = 'none'
}
}
</script>
</body>
</html>
在这里,我想将ul 保留在body.div 中。我只想让它像带有自定义位置的组合框一样弹出。请参考附图。
当前设计:
我希望它是这样的:
如何使用 CSS 制作它?提前谢谢大家...
【问题讨论】:
标签: html css combobox customization