qwerty1 Asked:2022-03-15 04:19:05 +0000 UTC2022-03-15 04:19:05 +0000 UTC 2022-03-15 04:19:05 +0000 UTC 如何将一个 div 放在其他 div 之上? 772 如何将一个 div 放在其他 div 之上?要像图片中那样。需要位于其他 div 之上的 div 以蓝色突出显示(其余为白色)。 html 2 个回答 Voted Best Answer Daniil Kedrov 2022-03-15T04:31:09Z2022-03-15T04:31:09Z 使用 CSS 定位。在这种情况下,您需要为第二个白色块position: relative;设置属性,并为蓝色块设置属性position: absolute;,使其相对于第二个白色块定位。不要忘记包括top: 0;和 left: 0;。你可以在这里或这里阅读更多 Zhihar 2022-03-15T04:30:46Z2022-03-15T04:30:46Z position: absolute;使用and属性z-index: 100(例如 100,只是高于其余部分)来定位所需的块 .block { width: 100px; height: 25px; margin-bottom: 10px; border: 1px solid black; background: white; } .super { position: absolute; z-index: 100; top: 45px; width: 50px; height: 75px; background: rgba(0, 0, 255, 0.5); } <div class = 'block'></div> <div class = 'block'></div> <div class = 'block'></div> <div class = 'super'></div>
使用 CSS 定位。在这种情况下,您需要为第二个白色块
position: relative;设置属性,并为蓝色块设置属性position: absolute;,使其相对于第二个白色块定位。不要忘记包括top: 0;和left: 0;。你可以在这里或这里阅读更多position: absolute;使用and属性z-index: 100(例如 100,只是高于其余部分)来定位所需的块