[css2]高度不定的div垂直居中的问题。
知识要点:主要仿照table的居中来做,将div转化成table,依据display:table和display:table-cell。
父容器:display:table;
子容器:display:table-cell;vertical-align:middle;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body style="height:700px;background:#ccc;">
<div style="height:100%;width:100px;display:table">
<div style="display:table-cell;height:auto;width:100px;word-break:break-all;vertical-align:middle">
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
</div>
</div>
</body>
</html>
浙公网安备 33010602011771号