gpt4 book ai didi

html - 如何使一个div与其他div重叠?

转载 作者:太空狗 更新时间:2023-10-29 15:27:30 25 4
gpt4 key购买 nike

搜索栏下方的内容是在用户输入一些文本后显示的。目前,风格已达到我的目标。

然而,当我显示搜索结果时,它会将容器推到搜索栏后面,如我的图片所示:

enter image description here

我该怎么做才能让搜索结果显示并覆盖其下方的所有内容,不会将其他元素向下推?

这是我的 HTML:

<div id="search-bar" class="box">
<h1 class="horizontal-header">SEARCH THE DATABASE</h1>
<div id="search-wrapper">
<input name="query" id="name" class="big-search" placeholder="champion, item, spells..." />
<div id="search-results">
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
</div>
</div>
</div>

还有我的 CSS(用 LESS 编写):

  #search-bar {
width: 636px;
height: 35px;

#search-wrapper {
float:left;
margin-left: 13px;

#search-results {
z-index:999;
position:relative;


a {
display:block;

.item:hover {
background-color:#282828;
}

.item {
overflow: hidden;
background-color: #171717;
padding: 2px;
cursor:pointer;
margin-bottom:1px;

img {
float: left;
width: 35px;
}

.info {
float: left;
margin-left: 8px;

.name {
color: white;
margin: 0;
}

.description {
color: white;
margin: 0;
}
}
}
}
}
}
}

最佳答案

使用 CSS 的 Absolute Positioning .与相对定位不同,绝对定位将元素从文档流中移除(即防止它向下推其他东西。)

请记住,绝对定位的东西是相对于它最近定位的父级定位的 - 所以绝对定位的元素所在的任何容器(在你的情况下)都应该设置为 position:relative;

各类定位信息:http://www.w3schools.com/css/css_positioning.asp

关于html - 如何使一个div与其他div重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10089514/

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