DIV水平垂直居中
2017-09-19 10:46
169 查看
代码中包含:
1.固定宽高的DIV水平垂直居中
2.不固定宽高,通过before选择器实现的
3.不固定宽高,通过table布局实现的
4.不固定宽高,通过display:table实现的
5.不固定宽高,通过css3实现的
1.固定宽高的DIV水平垂直居中
2.不固定宽高,通过before选择器实现的
3.不固定宽高,通过table布局实现的
4.不固定宽高,通过display:table实现的
5.不固定宽高,通过css3实现的
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .block:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; } </style> </head> <body> <div style="position:relative;background: #00a0e9;width: 500px;height: 200px;"> <div style="position: absolute;background: #00cc66;width: 200px;height: 100px;left: 50%;top: 50%;margin-left: -100px;margin-top: -50px;"></div> </div> <div class="block" style="position:relative;text-align:center;background: #4b7ae9;width: 500px;height: 200px;"> <span>徐同保</span> </div> <table style="width: 500px;height:200px;background: #609a54"> <tr> <td style="text-align: center;vertical-align: middle;"> 徐同保 </td> </tr> </table> <div style="display: table;width: 500px;height:200px;background: #8e8e9a;"> <div style="display: table-cell;text-align: center;vertical-align: middle;"> 徐同保 </div> </div> <div style="justify-content: center;align-items: center;display:flex;background:#da4939;width: 500px;height:200px;"> 徐同保 </div> </body> </html>
相关文章推荐
- 让Div实现水平或垂直居中的相关方法
- css3中通过设置box-pack和box-align让div里面的各种元素垂直和水平居中的方法
- div中未知长宽的img的垂直水平居中
- div模块垂直水平居中
- HTML中一个div中关于其内容的水平和垂直居中
- div屏幕水平垂直居中
- 使div水平、垂直居中
- div+css:页面整体布局居中显示:上下居中||垂直居中,左右居中||水平居中
- 编写css让一个已知宽高的div元素水平居中?垂直居中
- 文字在div中的垂直居中问题 div在页面中的水平垂直居中问题 vertical-align ??????
- 水平/垂直都居中的div
- 实现 div 里面的内容div水平且垂直居中
- 关于div中图片水平垂直居中的问题
- 让div中的文字水平居中和垂直居中的css
- 不定高度div 在一定高度div内水平垂直居中
- 使用js实现div 水平垂直居中
- 如何让图片在垂直方向与 div的底部对齐 水平居中
- DIV水平居中、垂直居中
- css实现div内图片的垂直、水平居中
- CSS:使用CSS3将一个div水平和垂直居中显示