我需要一个自定义组合框。所以,我实施了ul
。问题是我无法通过单击在顶部打开组合框列表button
。展示的同时ul
,它移动button
到网页底部。
Code:
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制作它?谢谢大家...
尝试这个:
ul{
width: 100px;
background-color: rgb(224, 224, 224);
border-radius: 4px;
border: 1px solid black;
padding: 0;
margin: 0;
position: absolute;
bottom: 40px;
z-index: 9;
}
ul li{
list-style: none;
cursor: pointer;
padding: 4px 10px;
}
li:hover{
background-color: white;
}
div{
width: 100%;
height: 40px;
background-color: bisque;
position: relative;
}
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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)