给定以下HTML:
< div id = "容器" > <!——这里的其他元素——> < div id =“版权”> 版权所有Foo网页设计 < / div > < / div >
我想把#copyright贴在#container的底部。我能在不使用绝对定位的情况下实现这一点吗?
给定以下HTML:
< div id = "容器" > <!——这里的其他元素——> < div id =“版权”> 版权所有Foo网页设计 < / div > < / div >
我想把#copyright贴在#container的底部。我能在不使用绝对定位的情况下实现这一点吗?
当前回答
此外,如果有使用位置的规定:绝对;或者position:relative;,你总是可以尝试填充父div或放置margin-top:x;。在大多数情况下不是一个很好的方法,但在某些情况下可能会派上用场。
其他回答
CSS中没有所谓的float:bottom。最好的方法是在这种情况下使用定位:
position:absolute;
bottom:0;
如果你不知道子块的高度:
#{母公司 背景:绿色; 宽度:200 px; 身高:200 px; 显示:表格单元; vertical-align:底部; } .child { 背景:红色; vertical-align:底部; } < div id = "父" > < div class = "孩子" >的孩子 < / div > < / div >
http://jsbin.com/ULUXIFon/3/edit
如果你知道子块的高度,添加子块,然后添加padding-top/margin-top:
#{母公司 背景:绿色; 宽度:200 px; 身高:130 px; padding-top: 70 px; } .child { 背景:红色; vertical-align: 底; 身高:130 px; } < div id = "父" > < div class = "孩子" >的孩子 < / div > < / div >
显示:w3schools.com
有位置的元素:绝对的;定位相对于 最近的定位祖先(而不是相对于 视口,像固定)。
所以你需要将父元素定位为相对或绝对元素,等等,并将所需元素定位为绝对元素,然后将bottom设置为0。
#{容器宽度:100%;浮:左;位置:相对;} #{版权:绝对;底部:0 px;左:0 px;背景:# F00;宽度:100%;} #容器{背景:灰色;身高:100 px;} < div id = "容器" > <!——这里的其他元素——> < div id =“版权”> 版权所有Foo网页设计 < / div > < / div >
< div id = "容器" > <!——这里的其他元素——> < div id =“版权”> 版权所有Foo网页设计 < / div > < / div >
不要在底部使用"position:absolute"作为粘性页脚。那么你可以这样做:
html, body { height: 100%; margin: 0; } .wrapper { min-height: 100%; /* Equal to height of footer */ /* But also accounting for potential margin-bottom of last child */ margin-bottom: -50px; } .footer{ background: #000; text-align: center; color: #fff; } .footer, .push { height: 50px; } <html> <body> <!--HTML Code--> <div class="wrapper"> <div class="content">content</div> <div class="push"></div> </div> <footer class="footer">test</footer> </body> </html>