有时为了做一个很酷的演示页面,会需要用到绝对居中(水平+垂直)。
如果是像这样写,会有很大的局限性。
最近开始用这个自己摸索出来的方法来居中:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Perfect Centering</title>
<style>
html {
display:table;
height:100%;
width:100%;
}
body {
display:table-cell;
height:105px;
text-align:center;
vertical-align:middle;
width:418px;
}
</style>
</head>
<body>
<h1>I should've been centered and I'm cool with it.</h1>
</body>
</html>
What about IE? Just fuck off.
如果是像这样写,会有很大的局限性。
最近开始用这个自己摸索出来的方法来居中:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Perfect Centering</title>
<style>
html {
display:table;
height:100%;
width:100%;
}
body {
display:table-cell;
height:105px;
text-align:center;
vertical-align:middle;
width:418px;
}
</style>
</head>
<body>
<h1>I should've been centered and I'm cool with it.</h1>
</body>
</html>
What about IE? Just fuck off.