有没有办法只在CSS浏览器中心垂直对齐div?
答案 0 :(得分:1)
这是一种方法:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
html {
display: table;
width: 100%;
height: 100%
}
body {
display: table-row;
margin: 0;
height: 100%
}
#foo {
display: table-cell;
height: 100%;
vertical-align: middle
}
#test {
margin: auto;
background-color: #ccc
}
</style>
</head>
<body>
<div id="foo">
<div id="test">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</body>
</html>