【发布时间】:2011-12-20 04:13:50
【问题描述】:
我正在尝试使用this jsfiddle 使div 水平和垂直居中,保持浏览器宽度和高度的100%,其中文本应垂直和水平居中对齐,但目前是顶行的文本与中心对齐,而不是使整体中心点位于 3 行文本的中心。
有人知道怎么做吗?
我的 HTML:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Regret</title>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Gloria+Hallelujah|Bowlby+One+SC' rel='stylesheet' type='text/css'>
<link href='css/regret.css' rel="stylesheet">
</head>
<body>
<div id="container">
<div class="inner">
<h1>Regret</h1>
<p class="choice">Let it out</p>
<p class="choice">Wallow in it</p>
</div>
</div>
</body>
</html>
我的 CSS:
body { font-family: 'Gloria Hallelujah', cursive; margin:0; text-align:center; color: #5e7c88; }
h1, h2, h3 { font-family: 'Bowlby One SC', cursive; color: #4b5f6d; }
img { border: 0; }
#container { margin: 0 auto; }
.choice { font-family: 'Bowlby One SC', cursive; }
.inner { position: absolute; top: 50%; }
【问题讨论】: