标签:滚动 display items sla body ie9 logs 水平垂直 图片
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>未知宽高元素水平垂直居中</title> </head> <style> .parent1{ display: table; height:300px; width: 300px; background-color: #FD0C70; } .parent1 .child{ display: table-cell; vertical-align: middle; text-align: center; color: #fff; font-size: 16px; } </style> <body> <div class="parent1"> <div class="child">hello world-1</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>未知宽高元素水平垂直居中</title> </head> <style> .parent2{ height:300px; width: 300px; text-align: center; background: #FD0C70; } .parent2 span{ display: inline-block;; width: 0; height: 100%; vertical-align: middle; zoom: 1;/*BFC*/ *display: inline; } .parent2 .child{ display: inline-block; color: #fff; zoom: 1;/*BFC*/ *display: inline; } </style> <body> <div class="parent1"> <div class="child">hello world-1</div> </div> <div class="parent2"> <span></span> <div class="child">hello world-2</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>未知宽高元素水平垂直居中</title> </head> <style> .parent3{ position: relative; height:300px; width: 300px; background: #FD0C70; } .parent3 .child{ position: absolute; top: 50%; left: 50%; color: #fff; transform: translate(-50%, -50%); } </style> <body> <div class="parent3"> <div class="child">hello world-3</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>未知宽高元素水平垂直居中</title> </head> <style> .parent4{ display: flex; justify-content: center; align-items: center; width: 300px; height:300px; background: #FD0C70; } .parent4 .child{ color:#fff; } </style> <body> <div class="parent4"> <div class="child">hello world-4</div> </div> </body> </html>
<div id="wrapper"> <div id="likeImg"> <div class="content">Content goes here</div> </div> </div> #wrapper { display: table; } #likeImg { display: inline-block; vertical-align: center; }
<div class="box"> <div id="content"> Content goes here</div> </div> #content { position: absolute; top: 50%; height: 240px; margin-top: -120px; /* 盒子本身高度的一半 */ }
<div id="box"> <div id="content">Content here</div> <div id="floater"> </div> #floater { float: left; height: 50%; margin-bottom: -120px; } #content { clear: both; height: 240px; position: relative; }
<div id="box"> <div id="content"> Content here</div> </div> #content { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; height: 240px; width: 70%; }
标签:滚动 display items sla body ie9 logs 水平垂直 图片
原文地址:http://www.cnblogs.com/memphis-f/p/7349587.html