css实现块级元素水平和垂直居中

     
    <html lang=zh-cn> 
    <head> 
    <meta charset=utf-8> 
    <title>CSS实现块级元素水平垂直居中title> 
    <meta name=description content=CSS实现块级元素水平垂直居中> 
    <meta name=author content=Roc> 
    <meta name=copyright content=Roc> 
    <link rel=shortcut icon href=favicon.ico> 
    <link rel=apple-touch-icon href=custom_icon.png> 
    <meta name=viewport content=width=device-width, user-scalable=no > 
    <link rel=stylesheet href=main.css> 
    <style>
        body{
            background:#aabbcc;
        }

        .loginDiv{
            width:600px;
            border:1px dashed gray;
            border-radius:15px;
            padding:20px;
            position: absolute;
            top: 50%;
            left:50%;
            transform:translateX(-50%) translateY(-50%);
        }
    style>
    <script src=script.js>script> 
    head> 
    <body> 
        <div class="loginDiv">
            这里是正文部分
        div>
    body> 
    HTML> 

你可能感兴趣的:(CSS)