日期:2014-05-17 浏览次数:20639 次
div { height:25px; line-height:25px; overflow:hidden; }
<!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> <title> 单行文字实现垂直居中 </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { font-size:12px;font-family:tahoma;} div { height:25px; line-height:25px; border:1px solid #FF0099; background-color:#FFCCFF; } </style> </head> <body> <div>现在我们要使这段文字垂直居中显示!</div> </body> </html>
div { padding:25px; }
<!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> <title> 多行文字实现垂直居中 </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { font-size:12px;font-family:tahoma;} div { padding:25px; border:1px solid #FF0099; background-color:#FFCCFF; width:760px; } </style> </head> <body> <div><pre>现在我们要使这段文字垂直居中显示! div { padding:25px; border:1px solid #FF0099; background-color:#FFCCFF; } </pre></div> </body> </html>
div#wrap { height:400px; display:table; } div#content { vertical-align:middle; display:table-cell; border:1px solid #FF0099; background-color:#FFCCFF; width:760px; }
<!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> <title> 多行文字实现垂直居中 </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { font-size:12px;font-family:tahoma;} div#wrap { height:400px; display:table; } div#content { vertical-align:middle; display:table-cell; border:1px solid #FF0099; background-color:#FFCCFF; width:760px; } </style> </head> <body> <div id="wrap"> <div id="content"><pre>现在我们要使这段文字垂直居中显示! Webjx.Com div#wrap { height:400px; display:table; } div#co