2015-01-02 65 views
1

因此,我在inner-div内部有一个inner-div。我想要内部div作为页脚,所以它必须坚持外部div的底部。当外部div展开(高度)时,我希望页脚与外部div的底部一起移动。 我希望你明白我的意思?如何在inner-div底部固定一个内部div,以便在外部div扩展时移动

我该怎么做?

+0

不仅仅是'

outer
inner
'其他? div是块级别的,除非你覆盖或浮动或其他东西,否则宽度总是100%;或长度,你的意思是身高? –

+0

是的,我的意思是身高,对不起 – Bouss

+0

有几种不同的方法可以做到这一点,这取决于您的页面结构。谷歌搜索带来了许多不同的结果。 –

回答

1

这里是一个小提琴Fiddley de fiddly da

你想要的是:

#inner { 
    position:relative; 
    top: 80%; 
    width: 100%; 
    height: 100%; 
} 

#outer { 
    width:200px; 
    height: 100px; 
} 

希望它能帮助。愿代码与你同在。

+0

正是我在找的东西! – Bouss

+0

@Persijn顶部:80%似乎是一个任意值。你怎么知道该怎么做? – B2K

+0

你把它设置为从宽度剩下的。所以如果宽度是15%,那么最高需要85%。如果宽度30%的顶部是70%。你设置它的原因是因为它可以超越包含div。 – Persijn

1

下面是一个例子小提琴:http://jsfiddle.net/fdus48df/

#inner { 
    position: absolute; 
    bottom: 0; 
    height: 100px; 
    border: 2px solid red; 
    width: 100%; 
} 
#outer { 
    border: 2px solid blue; 
    position: relative; 
    height: 200px; 
} 

<button id="larger">Larger</button> 
<button id="smaller">Smaller</button> 
<div id="outer"> 
    <div id="inner"> 
    </div> 
</div> 

<script> 
    $(function() { 
     height = 200; 
     $('#larger').click(function() { 
      height += 10; 
      $('#outer').css('height',height+'px'); 
     }); 
     $('#smaller').click(function() { 
      height -= 10; 
      $('#outer').css('height',height+'px'); 
     }); 
    }); 
</script> 
相关问题