css面试题
1.盒子垂直居中的方法
#box{
width:400px;
height:400px;
position:absolute;
top:50%;
left:50%;
margin-left:-200px;
margin-top:-200px;
background:#000;
}
2.CSS实现首尾高度固定、中间高度自适应的DIV布局
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>Document</title> </head> <body> <div class="con"> <div class="top"></div> <div class="md"></div> <div class="bottom"></div> </div> <style> *{margin:0; padding:0;} html,body,.con{height:100%;width:100%;height:100%;width:100%;} div{position:absolute;} .top,.bottom{width:100%;height:100px;z-index:5;} .top{background:red;top:0;} .bottom{background:black;bottom:0;} .md{ width:100%; background:#a7fad7; overflow:auto; top:100px; bottom:100px; position:absolute; _height:100%; _border-top:-100px solid #eee; _border-bottom:-100px solid #eee; _top:0;/*http://www.cnblogs.com/ckmouse/archive/2012/02/14/2351043.html*/ } </style> </body> </html>
3.多行文字垂直居中
li{
display:table;
}
li>span{
display:table-cell;
vertical-align:middle;
}
4.设置图片宽度100%,高度等于宽度
img{
width:100%;
height:0;
padding-bottom:100%;
}
亦心晗