• 网页居中


    我看到有些网页在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之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    第二章
    第一章
    unity--实现新手引导功能
    golang MissingContentLength error
    遇到一个golang time.Tick的坑
    grpc client连接池及负载均衡实现
    Pytorch学习-线性回归
    Pytorch学习-自动求导
    Pytorch学习-线性代数实现
    天池Python训练营笔记—Python基础进阶:从函数到高级魔法方法
  • 原文地址:https://www.cnblogs.com/wpf123/p/2347366.html
Copyright © 2020-2023  润新知