You should change your approach, the element .box
used as a push-down margin is totally unnecessary, the paragraph p
that is the element we want to keep in the middle of the .container
should have a reset on its margins and the .container
should have a fixed height.
Finally, use flex-boxes:
.container {
height: 200px;
background: orange;
display: flex;
align-items: center;
justify-content: center;
}
.container p {
margin: 0;
background: cyan;
}
.container img {
width: 100px;
height: auto;
}
.wrapper {
padding-left: 20px;
}
<div class="container">
<img src="http://flaviusso.altervista.org/blog/wp-content/uploads/2013/11/html-css.jpg" alt="http://flaviusso.altervista.org/blog/wp-content/uploads/2013/11/html-css.jpg" />
<p>Hello World</p>
<div class="wrapper">
<img src="http://flaviusso.altervista.org/blog/wp-content/uploads/2013/11/html-css.jpg" alt="http://flaviusso.altervista.org/blog/wp-content/uploads/2013/11/html-css.jpg" />
<p>Hello World</p>
</div>
</div>