2012-04-10 90 views
5

搜索栏下方的内容旨在在用户输入一些文本后显示。目前,这种风格取决于我的目标。如何使div与其他divs重叠?

然而,当我将搜索结果显示,它推动以下搜索栏的容器,通过我的图片所示:

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(用更少的书面):

#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; 
          } 
         } 
        } 
       }     
      } 
     } 
    } 

回答

8

使用CSS的Absolute Positioning。与“相对定位”不同,“绝对定位”将文档中的项目从文档流中移除(即防止其将文档推向其他东西)。

请记住,绝对定位的东西相对于它最近的定位父 - 绝对定位的项目是(你的情况)应设置为position:relative;

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

6

position:absolute.item DIV。这样写:

.item { 
position:absolute; 
} 
+0

这工作,谢谢! :) – 2012-04-10 13:22:27