zoukankan      html  css  js  c++  java
  • 关于div的居中显示

    让一个大的div在页面居中显示:

    html代码如下:

    <body>
            <div id="container"></div>
    </body>

    不完善的方法:

    1、仅仅在IE浏览器中居中

    <style type="text/css" media="screen">
    *
    { padding: 0px; margin: 0px; }

    /**
    *仅仅在IE浏览器中居中
    / body
    { text-align: center; }

    #container { width:1100px; height: 500px; border: 1px solid #229; } </style>

    2、在IE浏览器外,其他的浏览器中居中

    <style type="text/css" media="screen">
                * {
                    padding: 0px;
                    margin: 0px;
                }
                
                #container {
                    width:1100px;
                    height: 500px;
                    border: 1px solid #229;
                    margin: auto; /* 在IE浏览器外的浏览器,实现居中 */
                    
                }
            </style>

    2、在所有的浏览器中居中

    <style type="text/css" media="screen">
                * {
                    padding: 0px;
                    margin: 0px;
                }
                
                #container {
                    width:1100px;
                    height: 500px;
                    border: 1px solid #229;

    /**
    *下面三局代码,实现所有浏览器的居中
    / position
    : absolute; left:50%; margin-left: -550px; /* #container宽度的一半*/ } </style>
  • 相关阅读:
    Centos/Docker/Nginx/Node/Jenkins 操作
    MyBatis 流式查询
    127.0.0.1
    Spring中的@Bean注解
    工厂模式
    webservice
    vs每次拉下一个控件都必选设置为绝对位置才可以移动,怎样解决啊
    ASP.NET AJAX 概述
    AJAX介绍
    时间控件
  • 原文地址:https://www.cnblogs.com/zhangbaowei/p/4748839.html
Copyright © 2011-2022 走看看