gpt4 book ai didi

javascript - 列表及其滚动条的不同 z-index

转载 作者:太空宇宙 更新时间:2023-11-04 11:23:00 26 4
gpt4 key购买 nike

我有一个小问题:

文件链接:http://codepen.io/anon/pen/WQvBBr

我有一个带有按钮的 html 文件,然后是一个链接列表。两个元素(按钮和列表)都位于页面的右侧,列表出现在按钮上方,因为它写在html文件中的按钮之后。两者都是可点击的。我的问题是关于滚动条的,它应该和列表一起出现在右边,但是他却出现在了按钮的后面。我试图通过将 z-index:-1 添加到按钮样式来解决它 (# Rand_users)它解决了它,但使按钮不可点击。

<html>
<head>
<meta charset="windows-1255">
<title>page</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css" />

</head>
<body>
<div id="fixed-header"></div>
<div id="center">
<button id="rand_users" style="bottom:-5px;left:1017px;" onclick="window.alert('button 4');">button 4</button>
<button id="rand_users" style="bottom:160px;left:1017px;" onclick="window.alert('button 9');">button 9</button>
<!-- <button id="rand_users" style="bottom:325px;left:1017px;" onclick="window.alert('button 12');">button 12</button> -->
<ul id="list" >
<li><a href="" onclick="window.alert('link1');" class="le" >1 </a></li>
<li><a href="" class="le" >2</a></li>
<li><a href="" class="le" >3</a></li>
<li><a href="" class="le" >4</a></li>
<li><a href="" class="le" >5</a></li>
<li><a href="" class="le" >6</a></li>
<li><a href="" class="le" >7</a></li>
<li><a href="" class="le" >8</a></li>
<li><a href="" class="le" >9</a></li>
<li><a href="" class="le" >10</a></li>
<li><a href="" class="le">11</a></li>
<li><a href="" class="le" >12</a></li>
<li><a href="" class="le" >13</a></li>
<li><a href="" class="le" >14</a></li>
<li><a href="" class="le" >15</a></li>
<li><a href="" class="le" >16</a></li>
<li><a href="" class="le" >17</a></li>
<li><a href="" class="le" >18</a></li>
<li><a href="" class="le" >19</a></li>
<li><a href="" class="le" >20</a></li>
</ul>
</div>
<div id="fixed-footer"></div>
</body>
</html>

CSS代码:

  div#fixed-header {
z-index:1;
height:120px;
position:fixed;
top:0px;
left:0px;
width:100%;
background:black;
}

div#center {
position:fixed;
top:120px;
bottom:35px;
width:100%;
background:white;
}

div#fixed-footer {
height:35px;
position:fixed;
bottom:0px;
left:0px;
width:100%;
background:black;
}

#list
{
list-style-type:none;
text-align:right;
list-style-position: inside;
overflow:hidden;
overflow-y:scroll;
height:100%;
}

#list a:hover {
color: black;
text-decoration: underline;
}

#rand_users
/* button */
{
/* z-index:-1; */
position:absolute;
width: 350px;
height: 170px;
background: yellow;
border: 5px solid blue;
}

.le {
display: inline-block;
position: relative;
background: grey;
padding: 5px 15px 5px 15px;
color: white;
font-size: 15px;
font-weight: bold;
}

.le:after {
content: '';
display: block;
position: absolute;
right: 100%;
top: 33%;
margin-top: -10px;
width: 0;
height: 0;
}

谢谢!

最佳答案

如果你唯一的问题是

My question is about the scrollbar, which should appear with the list on the right side, but he appears behind the buttons

然后尝试运行下面的代码片段,对您的片段稍作调整。

 div#fixed-header {
z-index:1;
height:10%;
position:fixed;
top:0px;
left:0px;
width:100%;
background:black;
}
div#center {
position:fixed;
top:10%;
bottom:35px;
width:100%;
background:white;
}
div#fixed-footer {
height:35px;
position:fixed;
bottom:0px;
left:0px;
width:100%;
background:black;
}

#list
{
list-style-type:none;
text-align:right;
list-style-position: inside;
overflow:hidden;
overflow-y:scroll;
height:100%;
position: fixed;
right: 0;
top: 10%;
width:80px;
}
#list > li {
min-width: 30px;
}
#list a:hover {
color: black;
text-decoration: underline;
}

.rand_users /* button */
{
position:absolute;
width: 350px;
height: 170px;
background: yellow;
border: 5px solid blue;
right: 0;
}

.le {
display: inline-block;
position: relative;
background: grey;
padding: 5px 15px 5px 15px;
color: white;
font-size: 15px;
font-weight: bold;
min-width: 25px;
}
.le:after {
content: '';
display: block;
position: absolute;
right: 100%;
top: 33%;
margin-top: -10px;
width: 0;
height: 0;
}
> 

<body>
<div id="fixed-header"></div>
<div id="center">

<button class="rand_users" style="bottom:-5px;" onclick="window.alert('button 4');">button 4</button>
<button class="rand_users" style="bottom:160px;" onclick="window.alert('button 9');">button 9</button>
<!-- <button id="rand_users" style="bottom:325px;left:1017px;" onclick="window.alert('button 12');">button 12</button> -->

<ul id="list" >
<li><a href="" onclick="window.alert('link1');" class="le" >1 </a></li>
<li><a href="" class="le" >2</a></li>
<li><a href="" class="le" >3</a></li>
<li><a href="" class="le" >4</a></li>
<li><a href="" class="le" >5</a></li>
<li><a href="" class="le" >6</a></li>

<li><a href="" class="le" >7</a></li>
<li><a href="" class="le" >8</a></li>
<li><a href="" class="le" >9</a></li>
<li><a href="" class="le" >10</a></li>

<li><a href="" class="le">11</a></li>
<li><a href="" class="le" >12</a></li>
<li><a href="" class="le" >13</a></li>
<li><a href="" class="le" >14</a></li>

<li><a href="" class="le" >15</a></li>
<li><a href="" class="le" >16</a></li>
<li><a href="" class="le" >17</a></li>

<li><a href="" class="le" >18</a></li>
<li><a href="" class="le" >19</a></li>
<li><a href="" class="le" >20</a></li>
</ul>
</div>


<div id="fixed-footer"></div>

</body>

关于javascript - 列表及其滚动条的不同 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32607844/

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