• DIV垂直居中 (转)


     

    第一种方法:

     1<style type="text/css">
     2<!--
     3#middle
     4{
     5       background:blue;
     6       position:absolute;
     7       left:expression((body.clientWidth-50)/2 + "px");
     8       top:expression((body.clientHeight-50)/2 + "px");
     9       width:50px;
    10       height:50px;
    11}

    12-->
    13
    </style>
    14<div id="middle"  align="absmiddle"></div> <!--absmiddle 图像的中间与同一行中最大元素的中间对齐。
    15-->

    说明:这段代码没有文档类型和命名空间的申明,我已试过,如果加上,蓝色方快儿将位于顶部且一部分被浏览器隐藏,大家可以试试!此外,FF不支持expression

    第二种方法:

     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
     5<title>DIV垂直居中</title>
     6<style type="text/css">
     7#menu
     8{
     9       position: absolute;
    10       top: 50%;
    11       left: 50%;
    12       margin-top: -25px;
    13       margin-left: -150px;
    14       color:blue;
    15       width: 300px;
    16       height: 50px;
    17       border:solid 1px gray;
    18}

    19
    </style>
    20</head>
    21<body>
    22<div id=menu>页面水平垂直居中</div>
    23</body>
    24</html>

    第三种方法:

     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
     5<title>DIV垂直居中</title>
     6<style type="text/css">
     7#menu
     8{
     9       position: absolute;
    10       top: 50%;
    11       left: 50%;
    12       margin-top: -25px;
    13       margin-left: -150px;
    14       color:blue;
    15       width: 300px;
    16       height: 50px;
    17       font-weight:bold;
    18       border:solid 1px gray;
    19       line-height:50px;
    20       font-size:20px; 
    21       text-align:center;
    22}

    23
    </style>
    24</head>
    25<body>
    26<div id=menu>页面水平垂直居中</div>
    27</body>
    28</html>
  • 相关阅读:
    HDU2363 最短路+贪心
    stl-----map去重,排序,计数
    STL------sort三种比较算子定义
    栈------表达式求值
    踩水坑系列一
    第一周 动态规划Dynamic Programming(一)
    模拟递归回溯贪心专题入门
    HDU1013,1163 ,2035九余数定理 快速幂取模
    HDU1005 找规律 or 循环点 or 矩阵快速幂
    入门基础常识
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1520668.html
Copyright © 2020-2023  润新知