2012-04-10 9 views
5

検索バーの下に表示される内容は、ユーザーがテキストを入力した後に表示されます。現在のスタイルは、私が目指しているものになります。私は、検索結果を表示したときに、私の絵で示されているようしかし、それは、検索バー、次のコンテナをプッシュdivを他のdivと重複させる方法は?

enter image description here

私は検索結果が表示されていることは何を行うことができますし、すぐ下のすべてをオーバーラップなし他の要素を下に押していますか?

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

答えて

8

使用CSSのAbsolute Positioning

は、ここに私のHTMLです。相対配置とは異なり、絶対配置はドキュメントのフローからアイテムを削除します(つまり、他のものを押し下げるのを防ぎます)。

絶対に配置されたものは、最も近い位置にある親に対して相対的に配置されます。 http://www.w3schools.com/css/css_positioning.asp

6

があなたの.item DIVにposition:absoluteを与える:絶対位置のアイテムは、位置決めのすべての種類のposition:relative;

情報に設定する必要があります(お使いの場合)です。このように書く:

.item { 
position:absolute; 
} 
+0

これはうまくいきました、ありがとう! :) –

関連する問題