Method 1
Idea: display setting parent element is: table, child element is: cell table, so you can use vertical align: Center to achieve horizontal center
Advantage: the parent element can dynamically change the height (the characteristic of table element)
Disadvantage: not supported under IE8

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Unknown width height element horizontal vertical center</title>
</head>
<style>
.parent1{
    display: table;
    height:300px;
    width: 300px;
    background-color: #FD0C70;
}
.parent1 .child{
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    color: #fff;
    font-size: 16px;
}
</style>
<body>
    <div class="parent1">
        <div class="child">hello world-1</div>
    </div>
</body>
</html>

Method two:

Idea: use an empty label span to set its vertical align baseline as the middle, and let it be inline block with a width of 0
Disadvantages: there is an empty tag that is useless. Display: inline blockie 6 7 is not supported (add: zoom1;*display:inline).
Of course, pseudo elements can also be used instead of span tags, but IE support is not good, but that's a later story

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Unknown width height element horizontal vertical center</title>
</head>
<style>
.parent2{
    height:300px;
    width: 300px;
    text-align: center;
    background: #FD0C70;
}
.parent2 span{
    display: inline-block;;
    width: 0;
    height: 100%;
    vertical-align: middle;
    zoom: 1;/*BFC*/
    *display: inline;
}
.parent2 .child{
    display: inline-block;
    color: #fff;
    zoom: 1;/*BFC*/
    *display: inline;
}
</style>
<body>
    <div class="parent1">
        <div class="child">hello world-1</div>
    </div>
    <div class="parent2">
        <span></span>
        <div class="child">hello world-2</div>
    </div>
</body>
</html>

Method three

Idea: absolute positioning of sub elements, 50% from the top and 50% from the left, then use css3 transform:translate(-50%; -50%)
Advantages: tall, can be used in the browser of webkit kernel
Disadvantage: IE9 is not supported. The following does not support the transform attribute

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Unknown width height element horizontal vertical center</title>
</head>
<style>
.parent3{
    position: relative;
    height:300px;
    width: 300px;
    background: #FD0C70;
}
.parent3 .child{
    position: absolute;
    top: 50%;
    left: 50%;
    color: #fff;
    transform: translate(-50%, -50%);
}
</style>
<body>
<div class="parent3">
        <div class="child">hello world-3</div>
    </div>
</body>
</html>

Method four:
Idea: use css3 flex layout
Advantages: simple and fast
Disadvantages: compatibility is not good. For details, see: http://caniuse.com/#search=flex

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Unknown width height element horizontal vertical center</title>
</head>
<style>
.parent4{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 300px;
    height:300px;
    background: #FD0C70;
}
.parent4 .child{
    color:#fff;
}
</style>
<body>div> <div class="parent4">
        <div class="child">hello world-4</div>
    </div>
</body>
</html>