zoukankan      html  css  js  c++  java
  • 网页居中

    我看到有些网页在IE里是居中的,可是到了Firefox里就靠左了,其实这个问题很简单,看下面这段代码:

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>网页居中</title>
    <style>
            body
            {
                    text-align:center;
            }
           
            div.window
            {
                    border:#330066 solid 1px;
                    800px;
                    height:700px;
                    margin-left:auto;
                    margin-right:auto;
            }
           
    </style>
    </head>

    <body>
            <div class="window"></div>
    </body>
    </html>

    复制上面的代码,保存为index.html,用浏览器浏览下效果,可以看到窗口永远是居中的
    原理是在你要居中的窗口(该例是window)的样式中添加margin-left:auto;margin-right:auto;让它左右空隙都自动,这样它就能自动居中对齐了
    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    基础DP(初级版)
    UVA-816.Abbott's Tevenge (BFS + 打印路径)
    1044: 数圈
    1049: 打牌
    1047: 小A的计算器
    1046: 最小的K个数
    1045: 愚人节的礼物
    1044: 数圈
    1043: 绩点计算
    1042: 小丑排序
  • 原文地址:https://www.cnblogs.com/wpf123/p/2347366.html
Copyright © 2011-2022 走看看