任意居中定位

<html>
<head>
<style>
        body{
            text-align:center;
            margin:auto;
            font-family:宋体;
        }
        #head,#nag2,#content{ position:relative; }
        #logo,#poster,#nag1,#flashshow,#hot{ position:absolute;}
        .bluetext{color:#2D60ED;}
        #head{1000px;height:170px;background-color:#fbe73b;}
        #headsideline{ 100%; height:10px; background-color:#ff2d1d;  }
        #logo{  300px; height:160px; background-color:#eee;  left:0px;     }
        #poster{    left:380px;    top:40px;    }
        #nag1{padding:5px;padding-left:15px;padding-right:15px;background-color:#eeeeee;left:500px;top:130px;color:#ff2d1d;font-size:14px;border:1px solid #ff2d1d;    }
        #nag1 a{color:#ff2d1d;}
        #nag1 a:hover{color:#1EA082;font-size:16px;}
        #nag2{background-color:#eee;1000px;height:30px;left:0px;    top:5px;    color:#ff2d1d;font-size:12px;border:1px solid #ff2d1d;text-align:left;}
        #nag21{padding-top:7px;padding-left:15px;padding-right:15px;}
        #content{top:10px;left:0px;1000px;}
        #flashshow{left:0px;top:0px;}
        #hot{left:645px;}
    </style>

</head>
<body>
<center>
        <body>
            <!-- 要再一个层里任意布局一个层,必须外嵌一个position为relative的层 -->
            <!-- 头部 -->
            <div id="head">
                <div id="headsideline">
                </div>
                <div id="logo">
                    <img src="images/logo.png" />
                </div>
                <div id="poster">
                    <img src="images/poster.gif" />
                </div>
                <div id="nag1">
                    <a href="#">我的点点</a>&nbsp;&nbsp;
                    <a href="#">快速点餐通道</a>&nbsp;&nbsp;
                    <a href="#">南京饮食</a>&nbsp;&nbsp;
                    <a href="#">大厨课堂</a>
                </div>
            </div>
            <!-- 中间的导航栏 -->
            <div id="nag2">
                <div id="nag21">
                    您当前所在地为:<label class="bluetext">南京理工大学</label>,
                    更改此项请<a href="#">点击这里</a>,或者直接
                    <a href="Javascript:void(0);" id="expandlist">展开列表</a>
                    以选择其他地区<a href="Javascript:void(0);" id="closelist">隐藏列表</a>
                </div>
                <div>
                </div>
            </div>
            <!-- 正文 -->
            <div id="content">
            <!-- flash展示位 -->
                <div id="flashshow">
                    <img src="images/flashshow.png" />
                </div>
                <div id="hot">
                    <div id="hottitle">
                        <img src="images/hot.png">
                    </div>
                    <div>
                    </div>
                </div>
            </div>
        </body>
    </center>

</body>
</html>


作者:水木    
 
原文地址:https://www.cnblogs.com/hsapphire/p/1610051.html