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>
  • 相关阅读:
    SharePoint REST API
    线程同步
    win32
    win32
    win32
    win32
    win32
    win32
    win32
    解决CentOS被wbew挖矿程序入侵的方法
  • 原文地址:https://www.cnblogs.com/zhangbaowei/p/4748839.html
Copyright © 2011-2022 走看看