【发布时间】:2015-01-09 11:23:58
【问题描述】:
我有 Bootstrap3 页面,中间的某处是全显示高度的行。如何垂直居中该行的内容?
我已经尝试了“vertical-align:center”css 属性,但这似乎不起作用('middle' 而不是 'center')。
这是一个小的live demo,或者作为一个独立的 HTML 示例:
<!DOCTYPE html><html><head><meta charset='utf-8'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css'>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js'></script>
<style type='text/css'>
.row { color:#ff0; }
.bg1 { background:#007; }
.bg2 { background:#060; }
.special { background:#600; height:100vh; vertical-align:center; }
</style>
</head><body>
<div class="container-fluid text-center">
<div class="row bg1">Top row<br><br></div>
<div class="row bg2">Another row<br>With some content<br><br></div>
<div class="row bg1">....Bla bla bla....<br>sadf asdf adsf asdf asdf<br><br></div>
<div class="row special">
<h2>Hello</h2>
This should be vertically centered
</div>
<div class="row bg2">And here's yet another row<br><br></div>
<div class="row bg1">The bottom row<br><br></div>
</div>
</body></html>
【问题讨论】:
-
多亏了两者,表格解决方案实际上运行良好!
标签: css twitter-bootstrap twitter-bootstrap-3 row vertical-alignment