2013-06-03 63 views
0

我试图隐藏另一个跨度下的跨度,当有人点击最上面的跨度时,它应该消失并显示下面的内容。点击显示范围

我的HTML:

<span id="couponCode" style="display:inline-block;border:2px dashed;padding:5px;margin:5px;background:#EE4000;color:white;height:20px;text-align:center;">{{ i.couponCode }}</span><span class="cTs">Click to see code</span> 

我的CSS:

.cTs 
{ 
    left :0px; 
    padding:10px; 
    height:50px; 
    color:white; 
    width: 100px; 
    position: relative; 
    background: black; 
} 

,但我无法定位在第一跨度......而是出现在第一区间的权利.. .. can someone can help me ...

+0

你可能需要定位'点击查看code'使用绝对定位。查看[绝对定位]的结果(http://jsfiddle.net/hJ983/)。根据需要调整它。 –

回答

2

将容器内的元素包装在position: relative;容器中,并使用position: absolute;topleft值fo [R内部元素

div { 
    position: relative; 
} 

div span { 
    position: absolute; 
    top: 0; 
} 

div span:nth-of-type(1) { 
    z-index: 1;  
} 

div span:nth-of-type(2) { 
    top: 10px; 
    left: 25px; 
} 

Demo

使用的onclick事件