html 中div垂直居中的三種方式
阿新 • • 發佈:2019-02-20
1.第一種:
- <style type="text/css">
- <!--
- .con_div{
- width:400px;
- height:300px;
- border:1px solid #777;
- text-align:center;
- display:table-cell;
- vertical-align:middle;
- background:red;
- color:#fff;
- line-height:300px;
- }
- -->
- </style>
- <div class="con_div">
- 測試內容ddddddddddd
- </div>
2.第二種:
- <style type="text/css">
- <!--
- .con_div{
- width:400px;
- height:300px;
- border:1px solid #777;
- text-align:center;
- display:table-cell;
- vertical-align:middle;
- background:red;
- color:#fff
- }
- /*FOR IE*/
- .fixie{
- width:0;
- height:100%;
- display:inline-block;
- vertical-align:middle;
- }
- -->
- </style>
- <div class="con_div">
- <span class="fixie"></span>
- 測試內容
- </div>
3.第三種:
- <style>
- #warp {
- position: absolute;
- width:500px;
- height:200px;
- left:50%;
- top:50%;
- margin-left:-250px;
- margin-top:-100px;
- border: solid 3px red;
- }
- </style>
- <body>
- <divid=warp>Test</div>
- </body>