2012-04-10 4 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

감사합니다! :) –

관련 문제