2014-06-13 3 views
2

메뉴가 겹치는 내용을 갖기 위해 노력하고 있지만 지금은 내용 상자를 멀리 옮깁니다.위치 지정 및 Z- 인덱스 관련 문제

나는 이미 position: relative 트릭을 시도했지만 문제는 사라지지 않는 것 같습니다. 그 해결책은 아마도 명백한 무언가 일 것이지만 그것을 찾는 데 도움이 필요합니다.

편집 : 죄송합니다, 추가하는 것을 잊어 버렸습니다. 상자도 크기 조정 가능()되어 절대 위치 지정을 피하려고합니다. EDIT2 : 신경 쓸, right:5px 해결되는 문제

JSFiddle

HTML

<div class="box"> 
    <div class="top"> 
     <div class="icon"></div> 
     <div class="menubox"> 
      <ul class="menu"> 
       <li><a href="#">Menu Option 1</a> 

       </li> 
       <li><a href="#">Menu Option 2</a> 

       </li> 
      </ul> 
     </div> 
    </div> 
    <div class="content"> 
     <p>content goes here</p> 
    </div> 

    <div class="content"> 
     <p>content goes here</p> 
    </div> 
</div> 

CSS

.box { 
    width: 400px; 
    height: 200px; 
    margin: 5px; 
    float: left; 
    background: LightGray; 
    border: 1px solid DarkGray; 
    overflow: hidden; 
} 
.top { 
    width: 100%; 
    height: 25px; 
    background: lightblue; 
} 
.icon { 
    float: right; 
    background: red; 
    height: 15px; 
    width: 15px; 
    margin: 5px; 
} 
.menubox { 
    float: right; 
    background: yellow; 
    position: relative; 
    z-index:100; 
    width: 150px; 
} 
.content { 
    width: 180px; 
    height: 165px; 
    margin: 0px 10px 47px; 
    float: left; 
    position: relative; 
    z-index: 0; 
    display: block; 
    background:DarkGray; 
} 
li { 
    list-style-type: none; 
    text-decoration: none; 
} 
ul { 
    margin:none; 
    padding:none; 
} 

JS/jQuery를

$('.icon').mouseover(function() { 
    $(".menu").show(); 
}); //toggle menu on hover 
$(".menu").mouseleave(function() { 
    $(this).hide(); 
}); 

답변

1

사용 position: absolute을? fiddle

.menubox { 
    float: right; 
    background: yellow; 
    position: relative; 
    z-index:100; 
    width: 150px; 
    top: 25px; 
    right: 5px; 
    position: absolute; 
} 
.box { 
    width: 400px; 
    height: 200px; 
    margin: 5px; 
    float: left; 
    background: LightGray; 
    border: 1px solid DarkGray; 
    overflow: hidden; 
    position: relative; /* add this */ 
} 

편집 : 더 나은 위치

+1

죄송합니다. 추가를 잊어 버리신 경우 해당 상자도 'resizable()'이됩니다. 따라서 절대 위치 지정을 피하려고합니다. – chargarg

+0

상자의 크기를 조정하면 여전히 오른쪽에 붙어있을 것이므로, 괜찮을 것입니다. [피들] (http://jsfiddle.net/Last1Here/CcVnL/17/). 상자가'resizable()'이라는 예제를 제공하면 도움이 될까요? – Last1Here

+0

사실 상자의 크기를 조정하면 '오른쪽 : 5px'가 작동합니다. – chargarg

1

노란색 menubox는 문서의 흐름을 방해하지 않도록 절대 배치해야합니다 (공간 차지).

는 줘 position:absolute;

는 또한 .box 소자는 상자에 position:relative 그래서 메뉴 상대적인 위치를 가질 필요가있다.

는 당신을 위해 바이올린을 업데이트 :

http://jsfiddle.net/CcVnL/11/

0

내가 코드를 업데이트 한 아래의 링크를 확인하십시오. "jsfiddle.net/CcVnL/9/"