实现 div 里面的内容div水平且垂直居中
2015-04-07 22:08
567 查看
方案一(最佳方案):
方案二(该方案必须已知indemo的宽度和高度):
方案三(不使用定位):
<!DOCTYPE HTML> <html> <head> <title>test</title> <meta charset="utf-8"> <style> #demo{ width:300px; height:300px; position: relative; background-color: #ff6600; } #indemo{ width:100px; height:100px; position: absolute; left:0;right:0;top:0;bottom:0; margin:auto; background-color: white; } </style> </head> <body> <div id = 'demo'> <div id = 'indemo'></div> </div> </body> </html>
方案二(该方案必须已知indemo的宽度和高度):
#demo{ width:300px; height:300px; position: relative; background-color: #ff6600; } #indemo{ width:100px; height:100px; position: absolute; left:50%; top:50%; margin-left: -50px; margin-top: -50px; background-color: white; }
方案三(不使用定位):
#demo{ width:300px; height:300px; display: table-cell; vertical-align: middle; background-color: #ff6600; } #indemo{ width:100px; height:100px; margin:0 auto; background-color: white; }
相关文章推荐
- 总结div里面水平垂直居中的实现方法
- 小div在大div里面水平垂直都居中的实现方法
- DIV水平垂直居中css实现代码
- css实现div水平、垂直居中
- css实现div水平、垂直居中兼容chrome、ie8
- CSS实现未知内容高度的垂直水平居中(改良版)
- 让Div实现水平或垂直居中的相关方法
- 纯css多种方法实现div中单行文字、多行文字及嵌套div垂直水平居中
- css div垂直水平居中实现
- 寥寥几行CSS:实现某个div在网页中垂直水平居中呢
- CSS实现DIV水平居中和上下垂直居中
- css 实现div 内容垂直居中
- css实现图片在div中水平和垂直居中(但图片宽高要小于div宽高)
- css div内容水平,垂直居中限制
- 用div+css实现水平垂直居中
- 使用CSS实现div的水平和垂直居中
- CSS实现图片水平垂直居中于DIV
- css实现div内容垂直居中
- div里的内容水平居中和垂直居中
- CSS:实现某个div在网页中垂直水平居中