gpt4 book ai didi

html - 在CSS中将一个div放在另一个div上

转载 作者:太空宇宙 更新时间:2023-11-04 09:32:20 28 4
gpt4 key购买 nike

我尝试使用 html 和 css 制作吉他图片。我使用了两个 div,一个 "id = frets" 用于音品,另一个 "id = strings_div" 用于字符串。然后将第二个 div 放在第一个 div 的顶部,以便我可以显示字符串。我在网上搜索了一下,好像应该把两个div的位置设置为absolute。然后将第二个 div 的 z-index 设置为 99,以便显示字符串。但是,在运行我的代码后,没有显示字符串。我不确定我做错了什么。

#fretLeftVoid,
#fret1,
#fret2,
#fret3,
#fret4,
#fret5,
#fret6,
#fret7,
#fret8,
#fret9,
#fret10,
#fret11,
#fret12,
#fret13,
#fret14,
#fret15,
#fret16,
#fret17,
#fret18,
#fret19,
#fret20,
#fretRightVoid {
position: relative;
float: left;
background: #755628;
border-right: 4px solid #C0C0C0;
height: 220px;
}
#fretLeftVoid {
width: 15px;
}
#fret1 {
width: 45px;
}
#fret2 {
width: 40px;
}
#fret3 {
width: 40px;
}
#fret4 {
width: 40px;
}
#fret5 {
width: 40px;
}
#fret6 {
width: 40px;
}
#fret7 {
width: 40px;
}
#fret8 {
width: 40px;
}
#fret9 {
width: 40px;
}
#fret10 {
width: 40px;
}
#fret11 {
width: 40px;
}
#fret12 {
width: 40px;
}
#fret13 {
width: 40px;
}
#fret14 {
width: 40px;
}
#fret15 {
width: 40px;
}
#fret16 {
width: 40px;
}
#fret17 {
width: 40px;
}
#fret18 {
width: 40px;
}
#fret19 {
width: 40px;
}
#fret20 {
width: 40px;
}
#fretfretRightVoid {
width: 40px;
}
#frets {
position: absolute;
background: #FFFF00;
height: 300px;
width: 950px;
}
#strings {
padding: 0;
}
#strings li {
height: 1px;
width: 60%;
margin: 20px 0px;
background: #f00;
list-style-type: none;
left: 0px;
float: left;
position: relative;
}
#strings_div {
z-index: 1;
}
#frets,
#strings_div {
position: absolute;
}
<div id="fret1">1</div>
<div id="fret2">2</div>
<div id="fret3">3</div>
<div id="fret4">4</div>
<div id="fret5">5</div>
<div id="fret6">6</div>
<div id="fret7">7</div>
<div id="fret8">8</div>
<div id="fret9">9</div>
<div id="fret10">10</div>
<div id="fret11">11</div>
<div id="fret12">12</div>
<div id="fret13">13</div>
<div id="fret14">14</div>
<div id="fret15">15</div>
<div id="fret16">16</div>
<div id="fret17">17</div>
<div id="fret18">18</div>
<div id="fret19">19</div>
<div id="fret20">20</div>
<div id="fretRightVoid">21</div>
</div>
<div id="strings_div">
<ul id="strings">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>

这是运行结果的快照。 enter image description here

最佳答案

为什么字符串是列表?哈哈

无论如何,您没有为您的 #strings_div 提供任何宽度,这意味着当您的字符串显示 60% 宽度时,那是 0 的 60%!

#fretLeftVoid, #fret1, #fret2, #fret3, #fret4, 
#fret5, #fret6, #fret7, #fret8, #fret9, #fret10,
#fret11, #fret12, #fret13, #fret14, #fret15, #fret16,
#fret17, #fret18, #fret19, #fret20,
#fretRightVoid {
position:relative;
float:left;
background: #755628;
border-right: 4px solid #C0C0C0;
height:220px;
}

#fretLeftVoid {
width:15px;
}

#fret1 {
width:45px;
}

#fret2 {
width:40px;
}

#fret3 {
width:40px;
}

#fret4 {
width:40px;
}

#fret5 {
width:40px;
}

#fret6 {
width:40px;
}

#fret7 {
width:40px;
}

#fret8 {
width:40px;
}

#fret9 {
width:40px;
}

#fret10 {
width:40px;
}
#fret11 {
width:40px;
}
#fret12 {
width:40px;
}

#fret13 {
width:40px;
}

#fret14 {
width:40px;
}

#fret15 {
width:40px;
}
#fret16 {
width:40px;
}

#fret17 {
width:40px;
}

#fret18 {
width:40px;
}

#fret19 {
width:40px;
}

#fret20 {
width:40px;
}

#fretfretRightVoid {
width:40px;
}

#frets {
position:absolute;
background: #FFFF00;
height:300px;
width:950px;
}


#strings {
padding:0;
}
#strings li {
height: 1px;
width: 60%;
margin: 20px 0px;
background: #f00;
list-style-type: none;
left:0px;
float:left;
position:relative;
}



#strings_div {
z-index:1;
width: 950px;
}

#frets, #strings_div {
position: absolute;
}
<div id = "frets">
<div id = "fretLeftVoid">0</div>
<div id = "fret1">1</div>
<div id = "fret2">2</div>
<div id = "fret3">3</div>
<div id = "fret4">4</div>
<div id = "fret5">5</div>
<div id = "fret6">6</div>
<div id = "fret7">7</div>
<div id = "fret8">8</div>
<div id = "fret9">9</div>
<div id = "fret10">10</div>
<div id = "fret11">11</div>
<div id = "fret12">12</div>
<div id = "fret13">13</div>
<div id = "fret14">14</div>
<div id = "fret15">15</div>
<div id = "fret16">16</div>
<div id = "fret17">17</div>
<div id = "fret18">18</div>
<div id = "fret19">19</div>
<div id = "fret20">20</div>
<div id = "fretRightVoid">21</div>
</div>
<div id = "strings_div">
<ul id = "strings">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>

关于html - 在CSS中将一个div放在另一个div上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40684702/

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