I'm trying to center a div horizontally and vertically inside another div. My problem is that on window resize the width and height of parent div changes. For that, I have problems to center the div in the center of the parent div. Here is a case where I the width and height of the parent div is defined:
<div id="parent" style="">
<div id="child">Foo foo</div>
</div>
And the ccs:
#child {
display: table;
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color:red;
width:50px;
height:50px
}
#parent{
background-color:blue;
width:400px;
height:400px;
}
I don't know why it's so difficult to achieve it? JSFIDDLE