<!DOCTYPE html>
<html lang="en">
<head>
<title>Vertical Centering with Equal Top and Bottom Padding</title> <meta charset="utf-8">
<meta name="description" content="" /> <style type="text/css">
#parent {
background: #ccc;
} /* horizontal centering */
#parent {
width: 400px;
margin: 20px auto;
} .child {
text-align: center;
background: #999;
color: #fff;
} /* vertical centering */
#parent {
padding: 5% 0;
} .child {
padding: 1% 0;
} body {
margin: 0px auto;
background-color: beige;
}
</style> </head> <body>
<form>
<div id="parent">
<div class="child">用户&nbsp;<input type="text" /></div>
<div class="child">密码&nbsp;<input type="text" /></div>
<div class="child"></div>
<div class="child" style="background: #ccc;">
<input type="submit" value="登录" style="width:80px;" /></div>
</div>
</form>
<script type="text/javascript">
var p = document.getElementById("parent"); resize_fn = function (e) { var zbody_height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight);
var zdiv_height = Math.max(p.scrollHeight, p.clientHeight);
var ztop = (zbody_height - zdiv_height) / 2; p.style.marginTop = ztop + "px";
}; //var w = document.getElementsByClassName("child");
var w = document.querySelectorAll(".child"); for (var i = 0; i < w.length;i++) { var oi = w.item(i); oi.style.background = "#ccc"; } //p.style.background = "beige";
resize_fn();
document.body.onresize = resize_fn;
</script>
</body>
</html>

垂直居中,水平居中html例子的更多相关文章

  1. Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案

    x 环境 { "Aspose.Words": {"Version":"18.x"} } 需求与难题 生成试卷的时候,如果数学题目中有特殊符号 ...

  2. [css]实现垂直居中水平居中的几种方式

    转自博客 http://blog.csdn.net/freshlover/article/details/11579669 居中方式: 一.容器内(Within Container) 内容块的父容器设 ...

  3. 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术

    Ⅰ.绝对定位居中(Absolute Centering)技术 我们经常用margin:0 auto来实现水平居中,而一直认为margin:auto不能实现垂直居中--实际上,实现垂直居中仅需要声明元素 ...

  4. [转] 盘点8种CSS实现垂直居中水平居中的绝对定位居中技术

    转自:http://blog.csdn.net/freshlover/article/details/11579669 Ⅰ.绝对定位居中(Absolute Centering)技术 我们经常用marg ...

  5. CSS3实现 垂直居中 水平居中 的技巧

    1 1 1 How To Center Anything With CSS Front End posted by Code My Views 1 Recently, we took a dive i ...

  6. 相册 垂直居中; 水平居中. 1)宽度 大于高度, 宽度 100%; 2) 高度 大于 宽度 , 高度100%; getimagesize , list --->line-height , text-align, vertical-align, max-height, max-width

    一: 效果: 1) 黑色 部分是 相框. 2) 图片 要实现 水平居中, 垂直居中 3) 如果 宽度 大于 高度 ,那么 宽度 100% ,如图1 , 高度 自适应 ,同时不能超过黑色相框的 高度 ; ...

  7. CSS3实现DIV垂直居中+水平居中的四种方法

    <div class="div1"> <div class="div2"></div> </div> html结 ...

  8. div垂直居中水平居中css

    width: 860px; height: 500px; position: absolute; margin-left: -430px; margin-top: -250px; top: 50%; ...

  9. div水平居中和垂直居中

    水平居中和垂直居中 水平居中包含两种情况:        块级元素的水平居中:margin:0px auto;        文字内容的水平居中:text-align: center;        ...

随机推荐

  1. 2016年10月12日 星期三 --出埃及记 Exodus 18:23

    2016年10月12日 星期三 --出埃及记 Exodus 18:23 If you do this and God so commands, you will be able to stand th ...

  2. out 传值

    public void Out(out int a, out int b) {//out相当于return返回值 //可以返回多个值 //拿过来变量名的时候,里面默认为空值 a=1; b=2; } s ...

  3. flume+hadoop

    摘自:http://www.kankanews.com/ICkengine/archives/130646.shtml

  4. C语言中的二维数组和数组指针的那些事

    其实很多人就想弄明白这个定义了的数组指针里面赋值给的a究竟是什么 a是一个列地址,那么*a是什么,*a还是个地址它存储了行地址.如果我们定义一个指针,那他就有点二级指针的味道.因为它存储的是一个地址, ...

  5. swift + jj实践

    1,UIButton里面的字体和图片左对齐 button.imageEdgeInsets = UIEdgeInsetsMake(0,180/2,0.0,320/2) let btnRect = but ...

  6. Linux用户应知应会的7个‘ls’命令的独特技巧

    在前面我们系列报道的两篇文章中,我们已经涵盖了关于‘ls’命令的绝大多数内容.本文时‘ls命令’系列的最后一部分.如果你还没有读过该系列的其它两篇文章,你可以访问下面的链接. Linux中的15个基本 ...

  7. CodeForces 451C Predict Outcome of the Game

    Predict Outcome of the Game Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  8. CodeForces 373B Making Sequences is Fun

    Making Sequences is Fun Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Cookie 总结

    设置Cookie //设置cookie Cookie cookie = new Cookie("TOM","111"); //设置有效期,默认秒为单位 cook ...

  10. CUBRID学习笔记 20 默认的并发规则

    默认的设置是ISOLATION LEVEL 3 语法 SET TRANSACTION ISOLATION LEVEL 3; 最笨.官网的图不错看图吧 session 1 session 2 ;auto ...