2017-02-21 49 views
-2

enter image description here如何將元素錨定到包含可變高度內容的div的底部?

我創建了此頁面,只使用HTML和CSS進行練習。我的問題是,按鈕(如註釋,手錶)根據包含div中其他文本的高度垂直移動,而不是停留在容器底部。我該如何解決這個問題?

+0

這看起來像Flexbox的教科書用例(https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes)。 –

+5

向我們顯示您的代碼;這可能對我們幫助你更有用。 –

+0

我做到了,男人,非常感謝 –

回答

0

我假設你包裝一下你的HTML這樣

<div class="box"> 
    <img></img> 
    <p></p> 
    <footer class="like"> 
</div> 

如果你做的相對包裝位置和頁腳位置絕對有底0,它應該工作。

.box { 
    position:relative; 
} 

.like { 
    position: absolute; 
    bottom: 0 
} 

看到https://www.w3schools.com/cssref/tryit.asp?filename=trycss_position_bottom

和div.absolute,請嘗試更改底部爲0px。

+0

它的作用,男人,非常感謝你。 –

相關問題