HTML

<div class="outer">
    <div class="main">
        <img src="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" alt="Homework" title="Homework" />
        我要水平垂直居中
    </div>
</div>

CSS

    *{
        margin: 0;
        padding: 0;
    }
    .outer{
        position: absolute;
        width: 100%;
        height: 100%;
        display: table;
    }
    .main{
        max-width: 700px;
        margin: 0 auto;
        display: table-cell;
        vertical-align: middle;
        text-align: center;
    }

ALL

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>不定大小的div水平垂直居中</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .outer{
            position: absolute;
            width: 100%;
            height: 100%;
            display: table;
            background: rgba(0,0,0,.5);
        }
        .main{
            max-width: 700px;
            margin: 0 auto;
            display: table-cell;
            vertical-align: middle;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="main">
            <img src="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" alt="Homework" title="Homework" />
            我要水平垂直居中
        </div>
    </div>

</body>
</html>