Maison >interface Web >tutoriel HTML >【求教】请问,如何用css3实现div自适应高度?_html/css_WEB-ITnose
页面的结构非常简单
<html><head></head><body><div class="header"></div><div class="content"></div><div class="footer"></div></body></html>
可以将footer {
position:fix;
bottom: 0
}
将footer一直贴在底部
可以将footer {
position:fix;
bottom: 0
}
将footer一直贴在底部
<html> <head> <title>自适应高度测试</title> </head> <style> html body { height: 100%; } .header { height: 100px; } .footer { position: fixed; bottom: 0; } </style><body><div class="header">This is header</div><div class="content">This is content</div><div class="footer">This is footer</div></body></html>
我原本是这么搞的:
<html> <head> <title>自适应高度测试</title> </head> <style> html body { height: 100%; } .header { height: 100px; } .footer { height: 100px; } .content { height: 100%; } </style><body><div class="header">This is header</div><div class="content">This is content</div><div class="footer">This is footer</div></body></html>
<html><head></head><body><div class="header"></div><div class="content"></div><div class="footer"></div></body></html>
display:box;
box-flex:
.content{ height:auto; min-height:600px;}
<html><head></head><body><div class="header"></div><div class="content"></div><div class="footer"></div></body></html>
display:box;
box-flex:
<html> <head> <title>自适应高度测试</title> </head> <style> html body { height: 100%; } .wrap { height: 100%; display: -webkit-box; display: -moz-box; display: box; -webkit-box-orient: vertical; -moz-box-orient: vertical; box-orient: vertical; } .header { height: 100px; } .footer { height: 100px; } .content { /*height: 100%;*/ -webkit-box-flex: 1; -moz-box-flex: 1; box-flex: 1; } </style><body> <div class="wrap"> <div class="header">This is header</div> <div class="content">This is content</div> <div class="footer">This is footer</div> </div></body></html>
.content{ height:auto; min-height:600px;}
.content{ height:auto; min-height:600px;}
display:box;
box-flex:
.content{ height:auto; min-height:600px;}